我因为调用执行查询的方法而得到该异常。问题是,它向我显示一个列不存在,实际上我将其重命名为数据库。奇怪的是,调用一直问我查询()的“Columns []”参数中的列,但如果我添加它,它会再次问我这个。我不明白。该列名为'bookmark_title',重命名为'title'你有任何提示吗?非常感谢你。
方法调用:
public Cursor bookmarksURLs(int user_id){
Cursor result;
String bookmarks="bookmarks";
String [] columns={"_id","bookmark_url","title","bookmark_title","fk_user_bookmark"};
String where = "fk_user_bookmark = 1";
try {
result = db.query(bookmarks,columns,where,null,null,null,null);
return result;
} catch (SQLiteException e){
Log.v("Query","Error en el query");
e.printStackTrace();
}
return null;
}
记录而不包括“bookmark_title”
10-22 17:42:34.604: INFO/ActivityManager(58): Starting activity: Intent { cmp=example.android.com/.BookmarkList }
10-22 17:42:34.824: INFO/System.out(335): Base de datos abierta
10-22 17:42:34.835: DEBUG/AndroidRuntime(335): Shutting down VM
10-22 17:42:34.835: WARN/dalvikvm(335): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): FATAL EXCEPTION: main
10-22 17:42:34.855: ERROR/AndroidRuntime(335): java.lang.RuntimeException: Unable to start activity ComponentInfo{example.android.com/example.android.com.BookmarkList}: java.lang.IllegalArgumentException: column 'bookmark_title' does not exist
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:521)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): Caused by: java.lang.IllegalArgumentException: column 'bookmark_title' does not exist
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:312)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:87)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at example.android.com.BookmarkList.onCreate(BookmarkList.java:22)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-22 17:42:34.855: ERROR/AndroidRuntime(335): ... 11 more
10-22 17:42:34.885: WARN/ActivityManager(58): Force finishing activity example.android.com/.BookmarkList
10-22 17:42:34.885: WARN/ActivityManager(58): Force finishing activity example.android.com/.AndroidBoorkmarksActivity
10-22 17:42:35.384: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{4508e9e0 example.android.com/.BookmarkList}
10-22 17:42:45.746: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44fd28a8 example.android.com/.AndroidBoorkmarksActivity}
10-22 17:42:45.765: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{4508e9e0 example.android.com/.BookmarkList}
记录包含“bookmark_title”
10-22 17:51:57.455: WARN/System.err(528): android.database.sqlite.SQLiteException: no such column: bookmark_title: , while compiling: SELECT _id, bookmark_url, title, bookmark_title, fk_user_bookmark FROM bookmarks WHERE fk_user_bookmark = 1
10-22 17:51:57.465: WARN/System.err(528): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
10-22 17:51:57.465: WARN/System.err(528): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
10-22 17:51:57.465: WARN/System.err(528): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
10-22 17:51:57.465: WARN/System.err(528): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
10-22 17:51:57.475: WARN/System.err(528): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
10-22 17:51:57.475: WARN/System.err(528): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
10-22 17:51:57.475: WARN/System.err(528): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
10-22 17:51:57.485: WARN/System.err(528): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
10-22 17:51:57.485: WARN/System.err(528): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
10-22 17:51:57.495: WARN/System.err(528): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
10-22 17:51:57.495: WARN/System.err(528): at example.android.com.DatabaseHandler.bookmarksURLs(DatabaseHandler.java:53)
10-22 17:51:57.495: WARN/System.err(528): at example.android.com.BookmarkList.onCreate(BookmarkList.java:17)
10-22 17:51:57.505: WARN/System.err(528): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-22 17:51:57.505: WARN/System.err(528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-22 17:51:57.505: WARN/System.err(528): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-22 17:51:57.505: WARN/System.err(528): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-22 17:51:57.515: WARN/System.err(528): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-22 17:51:57.515: WARN/System.err(528): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 17:51:57.515: WARN/System.err(528): at android.os.Looper.loop(Looper.java:123)
10-22 17:51:57.515: WARN/System.err(528): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-22 17:51:57.525: WARN/System.err(528): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 17:51:57.525: WARN/System.err(528): at java.lang.reflect.Method.invoke(Method.java:521)
10-22 17:51:57.525: WARN/System.err(528): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-22 17:51:57.525: WARN/System.err(528): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-22 17:51:57.525: WARN/System.err(528): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
您是否检查了数据库中的实际内容?您可以通过调用adb shell
然后导航到存储数据库的目录并执行sqlite3命令来执行此操作。您将能够检查数据库的确切内容。
请注意,您的数据库可能位于模拟器上的/data/data/you.package.name中。有关adb shell
命令和sqlite3命令的详细信息,请查看此documentation。它向您展示了如何在您的设备上获取shell并检查sqlite数据库。
答案 1 :(得分:0)
您的columns
数组同时包含"title"
和"bookmark_title"
:
String [] columns={"_id","bookmark_url","title","bookmark_title","fk_user_bookmark"};
但您说bookmark_title
现在称为title
。我猜你在columns
中不小心留下了一些东西,应该是这样的:
String [] columns={"_id", "bookmark_url", "title", "fk_user_bookmark"};