android - Failure delivering result ResultInfo after taking picture -


i have fragment allows take pictures. of fragments have regular picture, , picture. meaning use 2 different result codes picture taking. error when take use result_picture_extra code , seems random.

why getting error when use request_picture_extra? also, if helps, showing picture in popupwindow , doesn't show up.

fragment code

private static final int request_picture = 1; private static final int request_picture_extra = 2;  private void showextrapicture() {     imageview extraimage = (imageview) view.findviewbyid(r.id.extra_image);      if (step.getisreqpicturefinished()) {         try {             fileinputstream fis = getactivity().openfileinput(step.getextraimagefilename());             bitmap imgfromfile = bitmapfactory.decodestream(fis);             fis.close();             extraimage.setimagebitmap(imgfromfile);             extraimage.invalidate();         }          catch (filenotfoundexception e) { e.printstacktrace(); }          catch (ioexception e) { e.printstacktrace(); }     } }  @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);      if (requestcode == request_picture && resultcode == activity.result_ok) {         bundle extras = data.getextras();         bitmap image = (bitmap) extras.get("data");          imagehandler imagehandler = new imagehandler(getactivity());         string filename = imagehandler.writetofile(image, step.getchecklistid(), step.getorder(), false);         step.setimagefilename(filename);          finishstep();         showresult();         checkifallfinished();     }      if (requestcode == request_picture_extra && resultcode == activity.result_ok) {         bundle extras = data.getextras();         bitmap image = (bitmap) extras.get("data");          imagehandler imagehandler = new imagehandler(getactivity());         string filename = imagehandler.writetofile(image, step.getchecklistid(), step.getorder(), true);         step.setextraimagefilename(filename);          if (step.getreqpicture()) { step.setisreqpicturefinished(true); }         showextrapicture();         checkifallfinished();     } } 

stack trace

01-31 14:42:54.192: e/androidruntime(21536): fatal exception: main 01-31 14:42:54.192: e/androidruntime(21536): java.lang.runtimeexception: failure delivering result resultinfo{who=android:fragment:0, request=2, result=-1, data=intent { act=inline-data dat=content://media/external/images/media/3504 (has extras) }} activity {com.medusa.checkit.android/com.medusa.checkit.android.stepactivity}: java.lang.nullpointerexception 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activitythread.deliverresults(activitythread.java:3205) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activitythread.handlesendresult(activitythread.java:3248) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activitythread.access$1200(activitythread.java:143) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activitythread$h.handlemessage(activitythread.java:1289) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.os.handler.dispatchmessage(handler.java:99) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.os.looper.loop(looper.java:137) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activitythread.main(activitythread.java:4950) 01-31 14:42:54.192: e/androidruntime(21536):    @ java.lang.reflect.method.invokenative(native method) 01-31 14:42:54.192: e/androidruntime(21536):    @ java.lang.reflect.method.invoke(method.java:511) 01-31 14:42:54.192: e/androidruntime(21536):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1004) 01-31 14:42:54.192: e/androidruntime(21536):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:771) 01-31 14:42:54.192: e/androidruntime(21536):    @ dalvik.system.nativestart.main(native method) 01-31 14:42:54.192: e/androidruntime(21536): caused by: java.lang.nullpointerexception 01-31 14:42:54.192: e/androidruntime(21536):    @ com.medusa.checkit.android.stepfragment.showextrapicture(stepfragment.java:388) 01-31 14:42:54.192: e/androidruntime(21536):    @ com.medusa.checkit.android.stepfragment.onactivityresult(stepfragment.java:547) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activity.dispatchactivityresult(activity.java:5367) 01-31 14:42:54.192: e/androidruntime(21536):    @ android.app.activitythread.deliverresults(activitythread.java:3201) 01-31 14:42:54.192: e/androidruntime(21536):    ... 11 more 

read error message: nullpointerexception occurs inside showextrapicture(). that's why happens request_picture_extra code.

you need find what's null , why. on line 388, know, i'd bet on view being null.

whether or not anyway, shouldn't hold onto created root view (assuming view reference here is). find views attached activity each time need it:

getactivity().findviewbyid(r.id.extra_image); 

or fragment's root view works if r.id.extra_image held inside it:

getview().findviewbyid(r.id.extra_image); 

and, side note, should close resources in finally: see example in fileinputstream documentation.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -