Android cursor-Fehler : Stellen Sie sicher, dass der Cursor wird korrekt initialisiert, bevor der Zugriff auf Daten von ihm

Werde ich implementieren Sie die Methode zum abrufen der Aufzeichnung des strings, aber wenn es um die Ausführung , es stellt Runtime-Error-Log Katze angegeben. Würden Sie uns bitte sagen, wie korrekt initialisieren Sie den cursor ?

Logcat

07-08 10:10:34.620: D/result(8036): true
07-08 10:10:34.660: D/memalloc(8036): ion: Unmapping buffer  base:0x57c06000 size:466944
07-08 10:10:34.660: D/memalloc(8036): ion: Unmapping buffer  base:0x57d6c000 size:466944
07-08 10:10:34.660: D/memalloc(8036): ion: Unmapping buffer  base:0x57cbb000 size:466944
07-08 10:10:34.710: D/debug(8036): Order 87318702
07-08 10:10:34.710: D/pcDbHelper(8036): pcDbHelper com.example.recordandmovie.PhotoDbAdapter@412cad30
07-08 10:10:34.841: W/CursorWindow(8036): Window is full: requested allocation 1249663 bytes, free space 398939 bytes, window size 2097152 bytes
07-08 10:10:34.931: W/CursorWindow(8036): Window is full: requested allocation 1249663 bytes, free space 398939 bytes, window size 2097152 bytes
07-08 10:10:34.941: D/debug Cursor(8036): can be created
07-08 10:10:34.941: E/CursorWindow(8036): Failed to read row 0, column 1 from a CursorWindow which has 0 rows, 4 columns.
07-08 10:10:34.941: W/dalvikvm(8036): threadid=1: thread exiting with uncaught exception (group=0x40c051f8)
07-08 10:10:34.951: E/AndroidRuntime(8036): FATAL EXCEPTION: main
07-08 10:10:34.951: E/AndroidRuntime(8036): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.recordandmovie/com.example.recordandmovie.Main6}: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.os.Looper.loop(Looper.java:137)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.ActivityThread.main(ActivityThread.java:4519)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at java.lang.reflect.Method.invokeNative(Native Method)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at java.lang.reflect.Method.invoke(Method.java:511)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at dalvik.system.NativeStart.main(Native Method)
07-08 10:10:34.951: E/AndroidRuntime(8036): 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.
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.database.CursorWindow.nativeGetString(Native Method)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.database.CursorWindow.getString(CursorWindow.java:450)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at com.example.recordandmovie.Main6.onCreate(Main6.java:39)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.Activity.performCreate(Activity.java:4485)
07-08 10:10:34.951: E/AndroidRuntime(8036):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)

Unten ist meine Arbeit

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
import android.view.Menu;

public class Main6 extends Activity {

    private PhotoDbAdapter pcDbHelper;
    private String orderidGenerated;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main6);

        Intent intent = getIntent();

        if(intent!=null){
            orderidGenerated = intent.getStringExtra("order");
        }

        Log.d("debug" , "Order " + orderidGenerated);

        if(pcDbHelper ==null){
            pcDbHelper = new PhotoDbAdapter(this);
            pcDbHelper.open();
        }

        Log.d("pcDbHelper" , "pcDbHelper " + pcDbHelper);
        Cursor cur = pcDbHelper.fetchOrderByRef(orderidGenerated);
        if(cur!=null){
            cur.moveToFirst();

            Log.d("debug Cursor" , "can be created");
            Log.d("KEY_PHOTO_HKID_HEX" , cur.getString(1));
            Log.d("KEY_PHOTO_ADDRESS_HEX" , cur.getString(2));
            Log.d("KEY_PHOTO_BANK_HEX" , cur.getString(3));
            startManagingCursor(cur);

            cur.close();
        }else{
            Log.d("debug Cursor" , "cannot be created");
        }


    }



}


public Cursor fetchOrderByRef(String refno) throws SQLException {

    Cursor mCursor =

            mDb.query(true, DATABASE_TABLE, new String[] {                          
                    KEY_REFNO ,
                    KEY_PHOTO_HKID_HEX , 
                    KEY_PHOTO_ADDRESS_HEX , 
                    KEY_PHOTO_BANK_HEX
            },KEY_REFNO + "=" + refno, 
            null, null, null, null, null);

    return mCursor;

}
Schreibe einen Kommentar