Android app keeps crashing on phone when viewing image -


i'm writing android app keeps crashing when trying load image took app. asked before no 1 got me. in previous question told me write in "logcat", here is

     07-31 18:27:56.692: e/androidruntime(3803): fatal exception: main      07-31 18:27:56.692: e/androidruntime(3803): java.lang.runtimeexception:      unable resume activity {com.authorwjf.camera/com.authorwjf.camera.main}:      java.lang.runtimeexception: failure delivering result resultinfo{who=null,       request=0, result=-1, data=null} activity       {com.authorwjf.camera/com.authorwjf.camera.main}:        java.lang.nullpointerexception 

i'll post code used; got article in techrepublic, i'm ostensibly assuming works.

i don't know how fix nullpointerexception, i'm pretty sure code correct. compiles , i've had similar problems in past viewing photo. i'm beginner, advice appreciated. (again, made sure check permissions fine.)

package com.authorwjf.camera;

import java.io.file;  import android.app.activity; import android.content.contentresolver; import android.content.intent; import android.graphics.bitmap; import android.graphics.matrix; import android.net.uri; import android.os.bundle; import android.os.environment; import android.provider.mediastore; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; import android.widget.toast; import com.authorwjf.camera.r;   public class main extends activity implements onclicklistener {  private static final int take_picture = 0; private uri muri; private bitmap mphoto;   @override         public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); ((button) findviewbyid(r.id.snap)).setonclicklistener(this); ((button) findviewbyid(r.id.rotate)).setonclicklistener(this); 

}

     @override       public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch (requestcode) { case take_picture:     if (resultcode == activity.result_ok) {         getcontentresolver().notifychange(muri, null);         contentresolver cr = getcontentresolver();         try {             mphoto = android.provider.mediastore.images.media.getbitmap(cr, muri);             ((imageview)findviewbyid(r.id.photo_holder)).setimagebitmap(mphoto);         } catch (exception e) {             toast.maketext(this, e.getmessage(), toast.length_short).show();         }     } } 

}

@override       public void onclick(view v) { if (v.getid()== r.id.snap) {     intent = new intent("android.media.action.image_capture");     file f = new file(environment.getexternalstoragedirectory(),  "photo.jpg");     i.putextra(mediastore.extra_output, uri.fromfile(f));     muri = uri.fromfile(f);     startactivityforresult(i, take_picture); } else {     if (mphoto!=null) {         matrix matrix = new matrix();         matrix.postrotate(90);         mphoto = bitmap.createbitmap(mphoto , 0, 0, mphoto.getwidth(), mphoto.getheight(), matrix, true);         ((imageview)findviewbyid(r.id.photo_holder)).setimagebitmap(mphoto);     } } 

}


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -