java.lang.IllegalStateException:无法从CursorWindow读取行0,col -1-Android sqlite问题 [英] java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow - Android sqlite issue

查看:81
本文介绍了java.lang.IllegalStateException:无法从CursorWindow读取行0,col -1-Android sqlite问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to fetch two values from a table in sqlite db in android. I get the following exception:

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运行相同的查询时,它总是会给出正确的结果.

When I run the same query from sqliteman, it always gives the correct result.

我们非常感谢您为解决此问题提供的帮助

Any help in resolving this issue is much appreciated

表结构如下:

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源(在源中搜索使用表名请求列名").现在看看您的logcat输出.该句子所在的行包含您要的列名称:/mnt/sdcard/googleCheckout/Saxo Trader.apk.此值来自您的结果游标.当然,您的数据库不包含此库伦:-)

The third line is the problem. See your logcat output and the Android sources (search within the sources for "requesting column name with table name"). Now have a look at your logcat output. The line with this sentence contains the column name you are requesting: /mnt/sdcard/googleCheckout/Saxo Trader.apk. This value is coming from your result cursor. Of course your db doesn't contain this colunm :-)

替换行

     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"));

我还建议将代码用于从循环内到循环外获取索引.无需一遍又一遍地索要索引.

I also suggest to pull the code for getting the indices from within the loop to outside of the loop. No need to ask for the indices over and over again.

这篇关于java.lang.IllegalStateException:无法从CursorWindow读取行0,col -1-Android sqlite问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆