Android camera error Failure delivering result ResultInfo -
i'm trying camera work android app keep getting following error
02-07 22:30:48.217 13197-13197/com.example.romsm.lap e/androidruntime: fatal exception: main java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=intent { act=inline-data dat=content://media/external/images/media/8557 (has extras) }} activity {com.example.romsm.lap/com.example.romsm.lap.treequestionsactivity}: java.lang.nullpointerexception @ android.app.activitythread.deliverresults(activitythread.java:3510) @ android.app.activitythread.handlesendresult(activitythread.java:3553) @ android.app.activitythread.access$1200(activitythread.java:165) @ android.app.activitythread$h.handlemessage(activitythread.java:1374) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5455) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1187) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1003) @ dalvik.system.nativestart.main(native method)
i have tried can find online nothing seems fix it. code camera stuff.
btnphoto.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent takepictureintent = new intent(mediastore.action_image_capture); if (takepictureintent.resolveactivity(getpackagemanager()) != null) { // file file = new file(...); startactivityforresult(takepictureintent, activity_start_camera); // takepictureintent.putextra(mediastore.extra_output, uri.fromfile(file)); } } }); }
and
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == activity_start_camera) { if (data != null && resultcode == result_ok) { // image captured , saved file bundle extras = data.getextras(); bitmap imagebitmap = (bitmap) extras.get("data"); imageview.setimagebitmap(imagebitmap); } else { // user cancelled image capture or // image capture failed, advise user } } super.onactivityresult(requestcode, resultcode, data); }
this code make camera works. may try this.
private void activetakephoto() { intent takepictureintent = new intent(mediastore.action_image_capture); startactivityforresult(takepictureintent, request_image_capture); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch (requestcode) { case request_image_capture: if (requestcode == result_load_image && resultcode == result_ok & null != data) { bitmap thumbnail = (bitmap) data.getextras().get("data"); bytearrayoutputstream bytes = new bytearrayoutputstream(); thumbnail.compress(bitmap.compressformat.jpeg, 90, bytes); //to generate random file name string filename = "tempimg.jpg"; try { photo = (bitmap) data.getextras().get("data"); //captured image set in imageview imageview.setimagebitmap(photo); } catch (exception e) { e.printstacktrace(); } } }
Comments
Post a Comment