重命名的 SQLite 列出现非法参数异常
由于调用执行查询的方法,我收到了该异常。问题是它向我显示一列不存在,实际上我将其重命名并再次创建了数据库。奇怪的是,调用不断询问我 query() 的“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)
I'm getting that exception because of a calling to a method that executes a query. The thing is that it shows me that a column doesn't exists, and actually I renamed it an created again the database. Strangely, the calling keeps asking me the column in the "Columns[]" argument of query(), but if I add it, it keeps asking me that again. I don't understand. The column is named 'bookmark_title' renamed to 'title' Do you have any hint?. Thank you very much.
Method calling:
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;
}
Log without including of "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}
Log with including of "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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否检查过数据库中的实际内容?您可以通过调用
adb shell
然后导航到存储数据库的目录并执行 sqlite3 命令来完成此操作。您将能够检查数据库的确切内容。请注意,您的数据库可能位于模拟器上的 /data/data/you.package.name 中。有关
adb shell
命令和 sqlite3 命令的更多信息,请查看此 文档。它向您展示了如何准确地在您的设备上获取 shell 并检查 sqlite 数据库。Have you checked to see what's actually in your database? You can do that by calling
adb shell
then navigating to the directory where you database is stored, and executing the sqlite3 command. You'll be able to examine the exact contents of your database.Note that you're database is probably in /data/data/you.package.name on the emulator. For more information on the
adb shell
command and the sqlite3 command checkout this documentation. It shows you how exactly to get the shell on your device and examine the sqlite database.您的
columns
数组同时具有"title"
和"bookmark_title"
:但您说
bookmark_title
现在称为 <代码>标题。我猜你不小心在列
中留下了一些东西,它应该是这样的:Your
columns
array has both"title"
and"bookmark_title"
:but you say that
bookmark_title
is now calledtitle
. I'd guess that you've accidentally left something behind incolumns
and it should be this: