gpt4 book ai didi

来自 CursorWindow 的 java.lang.IllegalStateException : Couldn't read row 0, col -1 - Android sqlite 问题

转载 作者:行者123 更新时间:2023-12-01 14:33:32 24 4
gpt4 key购买 nike

我正在尝试从 android 中的 sqlite db 中的表中获取两个值。我收到以下异常:

05-22 04:13:05.432: I/ActivityManager(251): app/com.nykkos.personalize[INITIAL] app.idle/false
05-22 04:13:05.432: I/ActivityManager(251): START {cmp=com.nykkos.personalize/.screens.PackageInstaller} from pid 1613
05-22 04:13:05.463: W/audio_hw_primary(134): select_output_device e=0, h=0, s=2, b=0
05-22 04:13:05.502: I/ActivityManager(251): app/com.nykkos.personalize[RESUMED] app.idle/false ...realStartActivityLocked
05-22 04:13:05.526: E/SQLiteCursor(1613): requesting column name with table name -- /mnt/sdcard/googleCheckout/Saxo Trader.apk
05-22 04:13:05.526: E/SQLiteCursor(1613): java.lang.Exception
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.database.sqlite.SQLiteCursor.getColumnIndex(SQLiteCursor.java:192)
05-22 04:13:05.526: E/SQLiteCursor(1613): at com.nykkos.personalize.db.SQLiteDBHelper.GetSelectedApplicationUrlList(SQLiteDBHelper.java:263)
05-22 04:13:05.526: E/SQLiteCursor(1613): at com.nykkos.personalize.screens.PackageInstaller.onCreate(PackageInstaller.java:42)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.Activity.performCreate(Activity.java:4465)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.ActivityThread.access$600(ActivityThread.java:125)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1149)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.os.Looper.loop(Looper.java:137)
05-22 04:13:05.526: E/SQLiteCursor(1613): at android.app.ActivityThread.main(ActivityThread.java:4368)
05-22 04:13:05.526: E/SQLiteCursor(1613): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 04:13:05.526: E/SQLiteCursor(1613): at java.lang.reflect.Method.invoke(Method.java:511)
05-22 04:13:05.526: E/SQLiteCursor(1613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-22 04:13:05.526: E/SQLiteCursor(1613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-22 04:13:05.526: E/SQLiteCursor(1613): at dalvik.system.NativeStart.main(Native Method)
05-22 04:13:05.526: E/CursorWindow(1613): Failed to read row 0, column -1 from a CursorWindow which has 3 rows, 2 columns.
05-22 04:13:05.526: D/AndroidRuntime(1613): Shutting down VM
05-22 04:13:05.526: W/dalvikvm(1613): threadid=1: thread exiting with uncaught exception (group=0x40b0a1f8)
05-22 04:13:05.526: E/AndroidRuntime(1613): FATAL EXCEPTION: main
05-22 04:13:05.526: E/AndroidRuntime(1613): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nykkos.personalize/com.nykkos.personalize.screens.PackageInstaller}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1964)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.ActivityThread.access$600(ActivityThread.java:125)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1149)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.os.Looper.loop(Looper.java:137)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.ActivityThread.main(ActivityThread.java:4368)
05-22 04:13:05.526: E/AndroidRuntime(1613): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 04:13:05.526: E/AndroidRuntime(1613): at java.lang.reflect.Method.invoke(Method.java:511)
05-22 04:13:05.526: E/AndroidRuntime(1613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-22 04:13:05.526: E/AndroidRuntime(1613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-22 04:13:05.526: E/AndroidRuntime(1613): at dalvik.system.NativeStart.main(Native Method)
05-22 04:13:05.526: E/AndroidRuntime(1613): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.database.CursorWindow.nativeGetString(Native Method)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.database.CursorWindow.getString(CursorWindow.java:451)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
05-22 04:13:05.526: E/AndroidRuntime(1613): at com.nykkos.personalize.db.SQLiteDBHelper.GetSelectedApplicationUrlList(SQLiteDBHelper.java:263)
05-22 04:13:05.526: E/AndroidRuntime(1613): at com.nykkos.personalize.screens.PackageInstaller.onCreate(PackageInstaller.java:42)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.Activity.performCreate(Activity.java:4465)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-22 04:13:05.526: E/AndroidRuntime(1613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)
05-22 04:13:05.526: E/AndroidRuntime(1613): ... 11 more
05-22 04:13:05.526: W/ActivityManager(251): Force finishing activity com.nykkos.personalize/.screens.PackageInstaller
05-22 04:13:05.541: I/WindowManager(251): createSurface Window{42411fd0 paused=false}: DRAW NOW PENDING
05-22 04:13:06.025: W/ActivityManager(251): Activity pause timeout for ActivityRecord{41c0ee08 com.nykkos.personalize/.screens.PackageInstaller}
05-22 04:13:06.033: I/ActivityManager(251): app/com.nykkos.personalize[RESUMED] app.idle/true ...resumeTopActivityLocked

以下是我使用的代码:

public Map<String, String> GetSelectedApplicationUrlList() {

Cursor c = myDataBase.rawQuery("SELECT reco_index_user_action_download_file ," +
" reco_index_content_code from tbl_reco_index_contents where reco_index_content_type =" +
" 'Application/Widget' and reco_index_user_action_downloaded=1 and reco_index_user_action_installed =1 ",
null);

Map<String, String> sel = Collections
.synchronizedMap(new LinkedHashMap<String, String>());
if (c != null) {
if (c.moveToFirst()) {
do {
System.out.println("Url is"+c.getString(0));
System.out.println("Code is"+c.getString(1));
String url = c.getString(c.getColumnIndex(c.getString(0)));
String code = c.getString(c.getColumnIndex(c.getString(1)));
sel.put(code, url);
} while (c.moveToNext());
}

}
c.close();
return sel;
}

异常是从以下位置抛出的:

System.out.println("Url is"+c.getString(0));

当我从 sqliteman 运行相同的查询时,它总是给出正确的结果。

非常感谢任何解决此问题的帮助

表结构如下:

CREATE TABLE tbl_reco_index_contents (
id integer PRIMARY KEY,
reco_index_content_code char(10),
reco_index_content_type char(30),
reco_index_user_action_downloaded smallint,
reco_index_user_action_download_file char(50),
reco_index_user_action_installed smallint
)

最佳答案

第三行是问题所在。查看您的 logcat 输出和 Android sources (在源中搜索“请求带有表名的列名”)。现在看一下 logcat 输出。包含这句话的行包含您请求的列名称:/mnt/sdcard/googleCheckout/Saxo Trader.apk。该值来自您的结果光标。当然,您的数据库不包含此列:-)

替换行

     String url = c.getString(c.getColumnIndex(c.getString(0)));
String code = c.getString(c.getColumnIndex(c.getString(1)));

     String url = c.getString(c.getColumnIndex("reco_index_user_action_download_file"));
String code = c.getString(c.getColumnIndex("reco_index_content_code"));

我还建议将用于获取索引的代码从循环内拉到循环外。无需一遍又一遍地询问索引。

关于来自 CursorWindow 的 java.lang.IllegalStateException : Couldn't read row 0, col -1 - Android sqlite 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16683453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com