Membuat upload foto di android studio?

ini letak masalah saya :

private String getRealPathFromURIPath(Uri contentURI, Activity activity) {
        Cursor cursor = activity.getContentResolver().query(contentURI, null, null, null, null);
        if (cursor == null) {
            return contentURI.getPath();
        } else {
            cursor.moveToFirst();
            int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
            return cursor.getString(idx);
        }
    }

ini erorr di logcatnya :

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mozeeb.schoolreport, PID: 8853
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://com.google.android.apps.docs.storage/document/acc=1;doc=24 flg=0x1 }} to activity {com.mozeeb.schoolreport/com.mozeeb.schoolreport.RegisterActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     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.
        at android.database.CursorWindow.nativeGetString(Native Method)
        at android.database.CursorWindow.getString(CursorWindow.java:438)
        at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
        at android.database.CursorWrapper.getString(CursorWrapper.java:137)
        at com.mozeeb.schoolreport.RegisterActivity.getRealPathFromURIPath(RegisterActivity.java:225)
        at com.mozeeb.schoolreport.RegisterActivity.onActivityResult(RegisterActivity.java:259)
        at android.app.Activity.dispatchActivityResult(Activity.java:7276)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

itu kenapa ya pas saat saya mau ambil gambar dari galeri trs pas gambarnya ku pilih dan terjadi error seperti itu

avatar Mujiburrohman
@Mujiburrohman

9 Kontribusi 0 Poin

Diperbarui 5 tahun yang lalu

1 Jawaban:

Mungkin link diskusi stackoverflow ini bisa membantu gan <a href=' https://stackoverflow.com/questions/22607019/nullpointerexcepiton-on-cursor-while-selecting-photo-from-gallery-on-dialog-frag '>Nullpointerexcepiton on cursor</a>

avatar IfanZalukhu
@IfanZalukhu

217 Kontribusi 158 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban