Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite在android上没有插入这样的列错误_Android_Database_Sqlite_Error Handling - Fatal编程技术网

SQLite在android上没有插入这样的列错误

SQLite在android上没有插入这样的列错误,android,database,sqlite,error-handling,Android,Database,Sqlite,Error Handling,从CSV插入数据时出现问题。CSV部分工作,但插入返回以下错误。基本上,它说不存在列。下面是代码,也是数据库的代码 09-06 17:52:22.725: E/AndroidRuntime(19168): FATAL EXCEPTION: main 09-06 17:52:22.725: E/AndroidRuntime(19168): android.database.sqlite. SQLiteException: no such column: Ananas (code 1): , wh

从CSV插入数据时出现问题。CSV部分工作,但插入返回以下错误。基本上,它说不存在列。下面是代码,也是数据库的代码

09-06 17:52:22.725: E/AndroidRuntime(19168): FATAL EXCEPTION: main

09-06 17:52:22.725: E/AndroidRuntime(19168): android.database.sqlite.
SQLiteException: no such column: Ananas (code 1): , while compiling: 
INSERT INTO food (name, sacharides, glycemia, category1) VALUES    
(Ananas, 13, 45,1)

09-06 17:52:22.725: E/AndroidRuntime(19168):    
at android.database.sqlite.SQLiteConnection.nativePrepareStatement
(Native Method)
下面是失败的代码

            FoodDatabase myHelper = new FoodDatabase(getApplicationContext());
            myDatabase = myHelper.getReadableDatabase();

            String[] nextLine;
            try {
                while ((nextLine = reader.readNext()) != null) {
                    // nextLine[] is an array of values from the line
                    System.out.println(nextLine[0]+ " " + nextLine[1]
                            +" "+ nextLine[2]);

                    String sql =   "INSERT INTO food (name, sacharides, glycemia, category1) " +
                            "VALUES (" + nextLine[0] + ", " + nextLine[1] + ", "  + nextLine[2]+ "," + nextLine[3] +")";
                //  myDatabase.rawQuery(sql, null);
                    myDatabase.execSQL(sql);
                }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
下面是数据库的外观

public class FoodDatabase extends SQLiteOpenHelper {

  public static final String TABLE_FOOD = "food";
  public static final String COLUMN_ID = "id";
  public static final String COLUMN_NAME = "name";
  public static final String COLUMN_SACHARIDES = "sacharides";
  public static final String COLUMN_SACHARIDESPORTION = "sacharides_per_portion";
  public static final String COLUMN_PORTIONSIZE = "portion_size";
  public static final String COLUMN_GLYCEMIA = "glycemia";
  public static final String COLUMN_CATEGORY1 = "category1";
  public static final String COLUMN_CATEGORY2 = "category2";
  public static final String COLUMN_CATEGORY3 = "category3";




  private static final String DATABASE_NAME = "tables.db";
  private static final int DATABASE_VERSION = 1;

  // Database creation sql statement
  private static final String DATABASE_CREATE = "create table "
      + TABLE_FOOD + "(" + COLUMN_ID
      + " integer primary key autoincrement, " + COLUMN_NAME
      + " text," + COLUMN_SACHARIDES
      + " real," + COLUMN_PORTIONSIZE
      + " integer," + COLUMN_SACHARIDESPORTION
      + " real," + COLUMN_GLYCEMIA
      + " integer,"+ COLUMN_CATEGORY1
      + " integer," +COLUMN_CATEGORY2
      + " integer," +COLUMN_CATEGORY3
      + " integer);";

  public FoodDatabase(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(FoodDatabase.class.getName(),
        "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_FOOD);
    onCreate(db);
  }

我不确定,但您可能需要在
内的字符串周围加上单引号
'
。 尝试:

就我而言

很遗憾,表名不匹配。:^)
休息一下。继续

事实上,问题似乎更深,当我把血糖放在一边时,它是有效的,但当我一次添加4个东西时,无论我如何改变位置,它都会失败,等等,你能说得具体一点吗?失败意味着什么?您得到的错误消息是什么?它返回它不知道列glycemia,或者如果我更改它,使其也插入到category2中,使其看起来插入到食品(名称、糖类、category1、category2)值(ananas,10,12,14)中,它说它不知道列category2首先,当您创建表
COLUMN\u CATEGORY1+“integer”+COLUMN\u CATEGORY2+“integer”+COLUMN\u CATEGORY3
时,是否需要将
放在
integer
之后?其他问题,您是否已在近期内更新了表格格式?删除它,然后重新创建,如果可以的话。我已经编辑了它,已经找到了:)但它没有帮助。哦,是的,删除数据库格式很好。我该怎么做?
String sql = "INSERT INTO food (name, sacharides, glycemia, category1) " +
                            "VALUES ('" + nextLine[0] + "', '" + nextLine[1] + "', '"  + nextLine[2]+ "', '" + nextLine[3] +"' )";