涉及SQLite方面的另一个Java问题。
我已经运行了我的应用程序,一切都很好,直到我来添加插入的数据。我在'12 -31 22:54:51.133的Log cat中收到错误:I / Database(273):sqlite返回:错误代码= 1,msg =没有这样的表:peopleTable'。这显然导致我无法使用我的插入方法添加到数据库中。
我尝试重命名数据库,我看不到我的表创建语句或我的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);
}
和logcat:
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)
答案 0 :(得分:6)
KEY_HOTNESS + "TEXT NOT NULL);");
看起来可能会导致问题。 2个字符串值之间是否有空格(" "
),就像表声明中的其他列一样?
答案 1 :(得分:4)
将EXCISTS
更改为EXISTS
它会起作用(或者至少会解决您的一个问题)
;)
答案 2 :(得分:0)
Ty为你们提供帮助。调整为你们看到的错误的组合,以及我在upGrade上使用相同数据库版本的事实。