android - NullPointerException when saving Bitmap to SD card -
i'm trying take picture , save sd, @ point (after photo has been taken) nullpointerexception. here's code:
package com.social.bearv2; import java.io.file; import java.io.ioexception; import java.text.simpledateformat; import java.util.date; import android.net.uri; import android.os.bundle; import android.os.environment; import android.provider.mediastore; import android.annotation.suppresslint; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imagebutton; import android.widget.imageview; import android.widget.toast; @suppresslint("newapi") public class articolo extends activity { private static final int capture_image_capture_code = 0; intent i; private button ib; private imageview imview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.article); ib = (button) findviewbyid(r.id.insert); imview = (imageview) findviewbyid(r.id.imview); ib.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { file photofile = null; try { photofile = createimagefile(); } catch (ioexception ex) { // error occurred while creating file } // continue if file created if (photofile != null) { intent = new intent(mediastore.action_image_capture); i.putextra(mediastore.extra_output, uri.fromfile(photofile)); startactivityforresult(i, capture_image_capture_code); } } }); } protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == capture_image_capture_code) { if (resultcode == result_ok) { try { toast.maketext(this, "image captured", toast.length_long).show(); bundle extras = data.getextras(); bitmap imagebitmap = (bitmap) extras.get("data"); imview.setimagebitmap(imagebitmap); } catch (nullpointerexception ex) { } } else if (resultcode == result_canceled) { toast.maketext(this, "cancelled", toast.length_long).show(); } } } private file createimagefile() throws ioexception { string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); string imagefilename = "bear_" + timestamp + ".jpg"; file photo = new file(environment.getexternalstoragedirectory(), imagefilename); return photo; } }
note line of code gives me exception "bundle extras = data.getextras();"
and logcat:
03-21 11:41:32.140: e/androidruntime(24225): fatal exception: main 03-21 11:41:32.140: e/androidruntime(24225): process: com.social.bearv2, pid: 24225 03-21 11:41:32.140: e/androidruntime(24225): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=0, result=-1, data=null} activity {com.social.bearv2/com.social.bearv2.articolo}: java.lang.nullpointerexception 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activitythread.deliverresults(activitythread.java:3385) 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activitythread.handlesendresult(activitythread.java:3428) 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activitythread.access$1300(activitythread.java:145) 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activitythread$h.handlemessage(activitythread.java:1254) 03-21 11:41:32.140: e/androidruntime(24225): @ android.os.handler.dispatchmessage(handler.java:102) 03-21 11:41:32.140: e/androidruntime(24225): @ android.os.looper.loop(looper.java:136) 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activitythread.main(activitythread.java:5081) 03-21 11:41:32.140: e/androidruntime(24225): @ java.lang.reflect.method.invokenative(native method) 03-21 11:41:32.140: e/androidruntime(24225): @ java.lang.reflect.method.invoke(method.java:515) 03-21 11:41:32.140: e/androidruntime(24225): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:791) 03-21 11:41:32.140: e/androidruntime(24225): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:607) 03-21 11:41:32.140: e/androidruntime(24225): @ de.robv.android.xposed.xposedbridge.main(xposedbridge.java:126) 03-21 11:41:32.140: e/androidruntime(24225): @ dalvik.system.nativestart.main(native method) 03-21 11:41:32.140: e/androidruntime(24225): caused by: java.lang.nullpointerexception 03-21 11:41:32.140: e/androidruntime(24225): @ com.social.bearv2.articolo.onactivityresult(articolo.java:61) 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activity.dispatchactivityresult(activity.java:5423) 03-21 11:41:32.140: e/androidruntime(24225): @ android.app.activitythread.deliverresults(activitythread.java:3381)
any suggestions?
here intent data
null
... stacktrace says data
null
...
resultinfo{who=null, request=0, result=-1, data=null // here}
and accessing null
instance @ bundle extras = data.getextras();
you not receive data when capture image passing output location. captured image saved @ location photofile
(the location created)...
Comments
Post a Comment