0

Androidのsqlite dbのテーブルから2つの値をフェッチしようとしています。次の例外が発生します。

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
)
4

1 に答える 1

1

3行目が問題です。logcat の出力とAndroid ソースを参照してください(ソース内で「テーブル名で列名を要求する」を検索してください)。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"));

また、ループ内からループ外にインデックスを取得するためのコードをプルすることもお勧めします。インデックスを何度も尋ねる必要はありません。

于 2013-05-23T19:30:06.607 に答える