SQLiteException: no such column: basal (code 1)

后端 未结 5 2016
予麋鹿
予麋鹿 2021-01-22 13:00

I\'m working with databases and I have the following DataBaseHandling class:

public class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables
//          


        
相关标签:
5条回答
  • 2021-01-22 13:36

    Use a space after KEY_BASAL column . As your table column name was not correct , the table was created without this column. So after modifying code re-install your database or change version.Then you will get correct table with columns

    String CREATE_MEASURES_TABLE = "CREATE TABLE " + TABLE_MEASURES + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_DATE + " TEXT,"
                + KEY_TIME_HOUR + " INTEGER NOT NULL," + KEY_TIME_MINUTE
                + " INTEGER NOT NULL," + KEY_BE_INTAKE + " REAL NOT NULL,"
                + KEY_GLUCOSE + " REAL NOT NULL," + KEY_BOLUS
                + " REAL NOT NULL," + KEY_BASAL + " REAL NOT NULL" + ")";
    
    
    if (cursor != null && cursor .getCount()>0){
    
            cursor.moveToFirst();
    
    ///
    
    }
    
    0 讨论(0)
  • 2021-01-22 13:36

    Remove , End of Query

    KEY_BASAL + "REAL NOT NULL," + ")";
                              ^
                              | Here
    

    And Use Space For Concat Strings

    KEY_BASAL + "REAL NOT NULL," + ")";
                 ^
                 | Here
    

    GoodLuck

    0 讨论(0)
  • 2021-01-22 13:42

    I got this error while using junit tests. And my error was simple but evil.

    I mixed getContext() and getMockConetext().

    0 讨论(0)
  • 2021-01-22 13:43

    There is a problem that you have missed a space at the Key_basal and also placed an extra comma at the end of your onCreate method. Your code :

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
    String CREATE_MEASURES_TABLE = "CREATE TABLE " + TABLE_MEASURES + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_DATE + " TEXT,"
            + KEY_TIME_HOUR + " INTEGER NOT NULL," + KEY_TIME_MINUTE
            + " INTEGER NOT NULL," + KEY_BE_INTAKE + " REAL NOT NULL,"
            + KEY_GLUCOSE + " REAL NOT NULL," + KEY_BOLUS
            + " REAL NOT NULL," + KEY_BASAL + "REAL NOT NULL," + ")";
    
    db.execSQL(CREATE_MEASURES_TABLE);
    }
    

    It should be :

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
    String CREATE_MEASURES_TABLE = "CREATE TABLE " + TABLE_MEASURES + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_DATE + " TEXT,"
            + KEY_TIME_HOUR + " INTEGER NOT NULL," + KEY_TIME_MINUTE
            + " INTEGER NOT NULL," + KEY_BE_INTAKE + " REAL NOT NULL,"
            + KEY_GLUCOSE + " REAL NOT NULL," + KEY_BOLUS
            + " REAL NOT NULL," + KEY_BASAL + " REAL NOT NULL" + ")";
    
    db.execSQL(CREATE_MEASURES_TABLE);
    }
    
    0 讨论(0)
  • 2021-01-22 13:54

    Autoincrement KEY_ID or put some data to KEY_ID as well as put your full log cat here:

    String CREATE_MEASURES_TABLE = "CREATE TABLE " + TABLE_MEASURES + "("
            + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_DATE + " TEXT,"
            + KEY_TIME_HOUR + " INTEGER NOT NULL," + KEY_TIME_MINUTE
            + " INTEGER NOT NULL," + KEY_BE_INTAKE + " REAL NOT NULL,"
            + KEY_GLUCOSE + " REAL NOT NULL," + KEY_BOLUS
            + " REAL NOT NULL," + KEY_BASAL + " REAL NOT NULL" + ")";
    
    0 讨论(0)
提交回复
热议问题