Android SQLLite表列丢失错误

Android SQLLite表列丢失错误,android,sqlite,Android,Sqlite,这是我要创建的代码: private static final String TABLE_CURRENT_GAME = "current"; private static final String C_KEY_ID = "C_id"; private static final String C_SCORE_1 = "C_score_1"; private static final String C_SCORE_2 = "C_score_2"; private st

这是我要创建的代码:

private static final String TABLE_CURRENT_GAME = "current";
    private static final String C_KEY_ID = "C_id";
    private static final String C_SCORE_1 = "C_score_1";
    private static final String C_SCORE_2 = "C_score_2";
    private static final String C_K_1 = "C_k_1";
    private static final String C_K_2 = "C_k_2";

public void onCreate(SQLiteDatabase db) {
            String CREATE_CURRENT_GAME_TABLE = "CREATE TABLE " + TABLE_CURRENT_GAME + "("
        + C_KEY_ID + " INTEGER PRIMARY KEY," + C_SCORE_1+"INT,"+C_SCORE_2+"INT,"+C_K_1+"INT,"+C_K_2+"INT)";

        db.execSQL(CREATE_CURRENT_GAME_TABLE);
    }

    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed

        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CURRENT_GAME);
        // Create tables again
        onCreate(db);
    }
以及我的插入代码:

void addCurrentGameData(CurrentGameTable data) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(C_SCORE_1, data.getScore1()); // score player1
        values.put(C_SCORE_2, data.getScore2());//score player2
        values.put(C_K_1, data.getKseres1());//kseres player1
        values.put(C_K_2, data.getKseres2());//kseres player2
        // Inserting Row
        db.insert(TABLE_CURRENT_GAME, null, values);
        db.close(); // Closing database connection
    }
其中CurrentGameData是我的构造函数

然后,当尝试这样插入表时:

 DatabaseHandler db = new DatabaseHandler(this);

         /**
          * CRUD Operations
          * */
         // Inserting Contacts
         Log.d("Insert: ", "Inserting ..");
         db.addCurrentGameData(new CurrentGameTable(1,2,3,4));
在我的手机中,我收到以下错误:

08-19 16:36:23.876: E/Database(3996): Error inserting current
08-19 16:36:23.876: E/Database(3996): android.database.sqlite.SQLiteException: table current has no column named C_score_2: , while compiling: INSERT INTO current(C_score_2, C_k_1, C_score_1, C_k_2) VALUES(?, ?, ?, ?);
08-19 13:48:19.036: E/AndroidRuntime(519): FATAL EXCEPTION: main
08-19 13:48:19.036: E/AndroidRuntime(519): android.database.sqlite.SQLiteException: no such table: current: , while compiling: SELECT  * FROM current
08-19 13:48:19.036: E/AndroidRuntime(519):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
在我的emulator中,我遇到以下错误:

08-19 16:36:23.876: E/Database(3996): Error inserting current
08-19 16:36:23.876: E/Database(3996): android.database.sqlite.SQLiteException: table current has no column named C_score_2: , while compiling: INSERT INTO current(C_score_2, C_k_1, C_score_1, C_k_2) VALUES(?, ?, ?, ?);
08-19 13:48:19.036: E/AndroidRuntime(519): FATAL EXCEPTION: main
08-19 13:48:19.036: E/AndroidRuntime(519): android.database.sqlite.SQLiteException: no such table: current: , while compiling: SELECT  * FROM current
08-19 13:48:19.036: E/AndroidRuntime(519):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)

使用相同语法创建的其他表可以正常工作,但第二个表不能正常工作。

转到设置->管理应用程序->您的应用程序->清除所有应用程序数据

在您将此列添加到表中之前,它可能正在使用手机中存储的旧表

例如:

C_SCORE_1+"INT,"
创建一个名为C_score_1INT的列,不带类型

您的代码应该是(添加空格):


它不起作用。同样的信息。该列分数_2不存在。