0

这张表有什么问题吗?

public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_FIRST_NAME + " TEXT,"
                + KEY_LAST_NAME + " TEXT," + KEY_MOB_NO + " TEXT,"
                + KEY_HOME_NO + " TEXT," + KEY_WORK_NO + " TEXT,"
                + KEY_HOME_ADDR + " TEXT," + KEY_EMAIL_ADDR + " TEXT,"
                + KEY_WORK_ADDR + " TEXT," + KEY_NOTES + " TEXT" + ");";
        db.execSQL(CREATE_CONTACTS_TABLE);

我的 logcat 说没有列。知道为什么会这样吗?

编辑:日志猫

09-28 07:47:48.933: E/SQLiteLog(1908): (1) table contacts has no column named home_address
09-28 07:47:48.953: E/SQLiteDatabase(1908): Error inserting home_address= first_name=543 work_address= mobile_number= work_number= last_name=543 notes= home_number= email_address=
09-28 07:47:48.953: E/SQLiteDatabase(1908): android.database.sqlite.SQLiteException: table contacts has no column named home_address (code 1): , while compiling: INSERT INTO contacts(home_address,first_name,work_address,mobile_number,work_number,last_name,notes,home_number,email_address) VALUES (?,?,?,?,?,?,?,?,?)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at com.example.contactmanager.DatabaseHandler.addContact(DatabaseHandler.java:80)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at com.example.contactmanager.NewContactActivity$1.onClick(NewContactActivity.java:63)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.view.View.performClick(View.java:4240)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.view.View$PerformClick.run(View.java:17721)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.os.Handler.handleCallback(Handler.java:730)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.os.Looper.loop(Looper.java:137)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at android.app.ActivityThread.main(ActivityThread.java:5103)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at java.lang.reflect.Method.invokeNative(Native Method)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at java.lang.reflect.Method.invoke(Method.java:525)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-28 07:47:48.953: E/SQLiteDatabase(1908):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

尝试卸载并再次运行该应用程序。可能是您在定义中添加了更多列,并且数据库已经安装,因此没有添加新列。onCreate方法仅在最初安装数据库时运行一次。它永远不会再次运行。当您需要升级时,有一个单独的方法onUpgrade- 但当您实际发布新版本时应该使用它。

于 2013-09-28T12:18:01.590 回答