1

另一个涉及 SQLite 方面的 Java 问题。

我已经运行了我的应用程序,一切都很好,直到我来添加插入的数据。我在“12-31 22:54:51.133: I/Database(273): sqlite returned: error code = 1, msg = no such table: peopleTable”的 Log cat 中收到错误。这显然导致了我不能使用我的插入方法添加到数据库的事实。

我尝试重命名数据库,但我的表创建语句或我的 onCreate/Upgrade 方法看不到任何问题。

继承人的代码:

代码:

public void onCreate(SQLiteDatabase db) {


        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_NAME + " TEXT NOT NULL, " +
                KEY_HOTNESS + "TEXT NOT NULL);");


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL("DROP TABLE IF EXCISTS" + DATABASE_TABLE);
        onCreate(db);
    }

和日志猫:

12-31 22:54:51.133: I/Database(273): sqlite returned: error code = 1, msg = no such    table: peopleTable
12-31 22:54:51.158: E/Database(273): Error inserting persons_hotness=5 persons_name=F
12-31 22:54:51.158: E/Database(273): android.database.sqlite.SQLiteException: no such table: peopleTable: , while compiling: INSERT INTO peopleTable(persons_hotness,  persons_name) VALUES(?, ?);
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
12-31 22:54:51.158: E/Database(273):    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
12-31 22:54:51.158: E/Database(273):    at com.example.sqliteexample.HotOrNot.createEntry(HotOrNot.java:174)
12-31 22:54:51.158: E/Database(273):    at com.example.sqliteexample.SQLiteExample.onClick(SQLiteExample.java:57)
12-31 22:54:51.158: E/Database(273):    at android.view.View.performClick(View.java:2408)
12-31 22:54:51.158: E/Database(273):    at android.view.View$PerformClick.run(View.java:8816)
12-31 22:54:51.158: E/Database(273):    at android.os.Handler.handleCallback(Handler.java:587)
12-31 22:54:51.158: E/Database(273):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-31 22:54:51.158: E/Database(273):    at android.os.Looper.loop(Looper.java:123)
12-31 22:54:51.158: E/Database(273):    at android.app.ActivityThread.main(ActivityThread.java:4627)
12-31 22:54:51.158: E/Database(273):    at java.lang.reflect.Method.invokeNative(Native Method)
12-31 22:54:51.158: E/Database(273):    at java.lang.reflect.Method.invoke(Method.java:521)
12-31 22:54:51.158: E/Database(273):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-31 22:54:51.158: E/Database(273):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-31 22:54:51.158: E/Database(273):    at dalvik.system.NativeStart.main(Native Method)
12-31 23:17:38.508: W/KeyCharacterMap(273): No keyboard for id 0
12-31 23:17:38.508: W/KeyCharacterMap(273): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-31 23:17:40.238: D/AndroidRuntime(273): Shutting down VM
12-31 23:17:40.238: W/dalvikvm(273): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-31 23:17:40.259: E/AndroidRuntime(273): FATAL EXCEPTION: main
12-31 23:17:40.259: E/AndroidRuntime(273): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.sqliteexample.SQLView }
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.app.Activity.startActivityForResult(Activity.java:2817)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.app.Activity.startActivity(Activity.java:2923)
12-31 23:17:40.259: E/AndroidRuntime(273):  at com.example.sqliteexample.SQLiteExample.onClick(SQLiteExample.java:94)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.view.View.performClick(View.java:2408)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.view.View$PerformClick.run(View.java:8816)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.os.Handler.handleCallback(Handler.java:587)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.os.Looper.loop(Looper.java:123)
12-31 23:17:40.259: E/AndroidRuntime(273):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-31 23:17:40.259: E/AndroidRuntime(273):  at java.lang.reflect.Method.invokeNative(Native Method)
12-31 23:17:40.259: E/AndroidRuntime(273):  at    java.lang.reflect.Method.invoke(Method.java:521)
12-31 23:17:40.259: E/AndroidRuntime(273):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-31 23:17:40.259: E/AndroidRuntime(273):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-31 23:17:40.259: E/AndroidRuntime(273):  at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

6
KEY_HOTNESS + "TEXT NOT NULL);");

看起来它可能会导致问题。2 个字符串值之间是否有空格 ( " "),就像表声明中的其他列一样?

于 2012-12-31T23:46:31.953 回答
4

更改EXCISTSEXISTS它会起作用(或至少会解决您的一个问题)
;)

于 2012-12-31T23:44:53.067 回答
0

泰为你的帮助家伙。调整为你们看到的错误的组合,加上我在 upGrade 上使用相同的数据库版本的事实。

于 2013-01-01T19:52:18.593 回答