android - java.lang.RuntimeException: Unable to resume activity -
what trying achieve on click of button should open camera ..the use clicks snap , returns app tubnail of clicked pic in image view
package com.example.waterbill; import java.io.bytearrayoutputstream; import java.io.file; import java.io.fileoutputstream; import java.io.ioexception; import android.app.activity; import android.content.intent; import android.content.pm.activityinfo; import android.graphics.bitmap; import android.os.bundle; import android.os.environment; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.imageview; import android.widget.toast; public class bill_meter_satus extends activity { @override protected void onresume() { // todo auto-generated method stub super.onresume(); } @override protected void onpause() { // todo auto-generated method stub super.onpause(); } button b1, b2; edittext edt1; imageview mimage; private static final int camera_pic_request = 1888; string values; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.bill_meter_sat); b1 = (button) findviewbyid(r.id.button1); b2 = (button) findviewbyid(r.id.button2); edt1 = (edittext) findviewbyid(r.id.edittext1); bundle = getintent().getextras(); if (extra != null) { values = extra.getstring("cons_code"); edt1.settext(values); toast.maketext(bill_meter_satus.this, values, toast.length_short) .show(); }
//onliclick of button caputre snap
b2.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub intent intent = new intent( android.provider.mediastore.action_image_capture); startactivityforresult(intent, camera_pic_request); } }); b1.setonclicklistener(new view.onclicklistener() { //on click of button move next activity @override public void onclick(view v) { // todo auto-generated method stub intent next = new intent( "com.example.waterbill.bill_meter_status_normal"); next.putextra("cons_code", values); startactivity(next); } }); } protected void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode != result_canceled) { if (requestcode == camera_pic_request) { // 2 bitmap thumbnail = (bitmap) data.getextras().get("data"); mimage.setimagebitmap(thumbnail); // 3 bytearrayoutputstream bytes = new bytearrayoutputstream(); thumbnail.compress(bitmap.compressformat.jpeg, 100, bytes); // 4 file file = new file(environment.getexternalstoragedirectory() + file.separator + "image.jpg"); try { file.createnewfile(); fileoutputstream fo = new fileoutputstream(file); // 5 fo.write(bytes.tobytearray()); fo.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } } } }
logcat
09-04 07:26:47.051: e/androidruntime(12992): fatal exception: main 09-04 07:26:47.051: e/androidruntime(12992): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1888, result=-1, data=intent { act=inline-data dat=content://media/external/images/media/18169 typ=image/jpeg (has extras) }} activity {com.example.waterbill/com.example.waterbill.bill_meter_satus}: java.lang.nullpointerexception 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activitythread.deliverresults(activitythread.java:3007) 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activitythread.handlesendresult(activitythread.java:3050) 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activitythread.access$1100(activitythread.java:127) 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activitythread$h.handlemessage(activitythread.java:1188) 09-04 07:26:47.051: e/androidruntime(12992): @ android.os.handler.dispatchmessage(handler.java:99) 09-04 07:26:47.051: e/androidruntime(12992): @ android.os.looper.loop(looper.java:137) 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activitythread.main(activitythread.java:4448) 09-04 07:26:47.051: e/androidruntime(12992): @ java.lang.reflect.method.invokenative(native method) 09-04 07:26:47.051: e/androidruntime(12992): @ java.lang.reflect.method.invoke(method.java:511) 09-04 07:26:47.051: e/androidruntime(12992): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:823) 09-04 07:26:47.051: e/androidruntime(12992): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:590) 09-04 07:26:47.051: e/androidruntime(12992): @ dalvik.system.nativestart.main(native method) 09-04 07:26:47.051: e/androidruntime(12992): caused by: java.lang.nullpointerexception 09-04 07:26:47.051: e/androidruntime(12992): @ com.example.waterbill.bill_meter_satus.onactivityresult(bill_meter_satus.java:88) 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activity.dispatchactivityresult(activity.java:4649) 09-04 07:26:47.051: e/androidruntime(12992): @ android.app.activitythread.deliverresults(activitythread.java:3003) 09-04 07:26:47.051: e/androidruntime(12992): ... 11 more
as logcat said:
07:26:47.051: e/androidruntime(12992): caused by: java.lang.nullpointerexception 09-04
it nullpointerexception
. don't see initialize mimage
. must initialize in oncreate()
method.
add code snippet oncreate()
method.
mimage = (imageview)findviewbyid(r.id.yourimageviewid);
Comments
Post a Comment