android - NullPointerException in onActivityResult after calling camera intent -


here's problem: need save photo default camera location, copy private location, add gps tags copy, , delete original photo. why around? because on devices, when using mediastore.extra_output in request intent photo saved in default location anyway. when application complete, when testing on new device (motorola mb526) crushes after accepting taken picture. same thing happens on emulator.

the thing is, in onactivityresult(int requestcode, int resultcode, intent data) data.getdata() returns null.

so question - there unified way save picture in given location , else?

edit:

capture image intent

protected void takephotos() {     intent imageintent = new intent(             android.provider.mediastore.action_image_capture);     startactivityforresult(imageintent, capture_image_activity_request_code); } 

and result

protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (resultcode == result_ok) {         if (requestcode == capture_image_activity_request_code) {             if (resultcode == result_ok && data != null) {                 uri capturedimageuri = data.getdata();                 log.d("cameraresult", "data =" + data.getdatastring());                 string capturedpicfilepath = getrealpathfromuri(capturedimageuri);                 writeimagedata(capturedimageuri, capturedpicfilepath);             } else if (resultcode == result_canceled) {                 toast.maketext(this, "picture not taken",                         toast.length_short).show();             } else {                 toast.maketext(this, "picture not taken",                         toast.length_short).show();             }         }     } }  public string getrealpathfromuri(uri contenturi) {     string[] projx = { mediastore.images.media.data };     cursor cursor;     if (build.version.sdk_int > build.version_codes.gingerbread_mr1) {         cursorloader loader = new cursorloader(this, contenturi, projx,                 null, null, null);         cursor = loader.loadinbackground();     } else {         cursor = this.managedquery(contenturi, projx, null, null, null);     }     int column_index = cursor             .getcolumnindexorthrow(mediastore.images.media.data);     cursor.movetofirst();     return cursor.getstring(column_index); } 

logcat output:

07-23 18:42:26.486: d/cameraresult(1744): data =null 07-23 18:42:26.486: d/androidruntime(1744): shutting down vm 07-23 18:42:26.486: w/dalvikvm(1744): threadid=1: thread exiting uncaught exception (group=0xb70334f0) 07-23 18:42:26.496: e/androidruntime(1744): fatal exception: main 07-23 18:42:26.496: e/androidruntime(1744): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1513, result=-1, data=intent { act=inline-data (has extras) }} activity {arios.e_gps/arios.e_gps.photos.photolistact}: java.lang.nullpointerexception 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activitythread.deliverresults(activitythread.java:2532) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activitythread.handlesendresult(activitythread.java:2574) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activitythread.access$2000(activitythread.java:117) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activitythread$h.handlemessage(activitythread.java:961) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.os.handler.dispatchmessage(handler.java:99) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.os.looper.loop(looper.java:130) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activitythread.main(activitythread.java:3683) 07-23 18:42:26.496: e/androidruntime(1744):     @ java.lang.reflect.method.invokenative(native method) 07-23 18:42:26.496: e/androidruntime(1744):     @ java.lang.reflect.method.invoke(method.java:507) 07-23 18:42:26.496: e/androidruntime(1744):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 07-23 18:42:26.496: e/androidruntime(1744):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 07-23 18:42:26.496: e/androidruntime(1744):     @ dalvik.system.nativestart.main(native method) 07-23 18:42:26.496: e/androidruntime(1744): caused by: java.lang.nullpointerexception 07-23 18:42:26.496: e/androidruntime(1744):     @ arios.e_gps.photos.photolistact.getrealpathfromuri(photolistact.java:316) 07-23 18:42:26.496: e/androidruntime(1744):     @ arios.e_gps.photos.photolistact.onactivityresult(photolistact.java:165) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activity.dispatchactivityresult(activity.java:3908) 07-23 18:42:26.496: e/androidruntime(1744):     @ android.app.activitythread.deliverresults(activitythread.java:2528) 07-23 18:42:26.496: e/androidruntime(1744):     ... 11 more 

edit

it's wrong did uri after action_image_capture , works me.

        bitmap picture = (bitmap) data.getextras().get("data");         bytearrayoutputstream stream = new bytearrayoutputstream();         picture.compress(bitmap.compressformat.jpeg, 100, stream);          string path = images.media.insertimage(getcontentresolver(), picture,                 "title" , null);         uri uriphoto = uri.parse(path); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -