android 5.1 - onActivityResult returning nullpointerexception by taking photo from camera -


i error when take image using camera :

java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=intent { act=inline-data (has extras) }} activity {ir.aflak.niaz/ir.aflak.niaz.newadd2}: java.lang.nullpointerexception: attempt invoke virtual method 'int android.graphics.bitmap.getwidth()' on null object reference                                                              @ android.app.activitythread.deliverresults(activitythread.java:3539)                                                              @ android.app.activitythread.handlesendresult(activitythread.java:3582)                                                              @ android.app.activitythread.access$1300(activitythread.java:144)                                                              @ android.app.activitythread$h.handlemessage(activitythread.java:1327)                                                              @ android.os.handler.dispatchmessage(handler.java:102)                                                              @ android.os.looper.loop(looper.java:135)                                                              @ android.app.activitythread.main(activitythread.java:5221)                                                              @ java.lang.reflect.method.invoke(native method)                                                              @ java.lang.reflect.method.invoke(method.java:372)                                                              @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899)                                                              @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)                                                           caused by: java.lang.nullpointerexception: attempt invoke virtual method 'int android.graphics.bitmap.getwidth()' on null object reference 

it works fine on pre lolipop android . code :

    protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         outputuri = data.getdata();         bitmap thepic = null;         try {             thepic = mediastore.images.media.getbitmap(newadd2.this.getcontentresolver(), outputuri);         } catch (exception e1) {             log.v("this", e1.getmessage());         }          fileoutputstream out = null;         bytearrayoutputstream bao = new bytearrayoutputstream();         double width = 0;         double height = 0;         width = thepic.getwidth();         height = thepic.getheight();  } 

the error in line : width = thepic.getwidth();

what problem ? should android 5 ?

thanks


Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -