android - App Crashes on a null object reference -


this question has answer here:

im new on android, , in app, need fill edittext, name, email, etc, add picture using button opens gallery or button takes picture , and after have push button send info db. works if add picture gallery, , send info, when same taking picture app crashes. im not sure problem , i'd appreciate me out. or tell me can causing problem.

 @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);      if(requestcode == cam_request && resultcode == activity.result_ok ){  try { bitmap = mediastore.images.media.getbitmap(getactivity().getcontentresolver(), (filepath)); getactivity().sendbroadcast(new intent(intent.action_media_scanner_scan_file, filepath)); } catch (ioexception e) {             e.printstacktrace();         }   }else if (requestcode == pick_image_request && resultcode == activity.result_ok ) {         filepath = data.getdata();         try {             bitmap = mediastore.images.media.getbitmap(getactivity().getcontentresolver(), filepath);             imageview.setimagebitmap(bitmap);              arealeyendaimagen.setvisibility(view.visible);             areafotocargada.setvisibility(view.visible);             imagencargada.setvisibility(view.visible);             textoimagencargada.setvisibility(view.visible);             area_cerrariagen.setvisibility(view.visible);             cerrarimagen.setvisibility(view.visible);             buttonchoose.seterror(null);          } catch (ioexception e) {             e.printstacktrace();         }     } }  public string getpath(uri uri) {     cursor cursor = getactivity().getcontentresolver().query(uri, null, null, null, null);     cursor.movetofirst();     string document_id = cursor.getstring(0);     document_id = document_id.substring(document_id.lastindexof(":") + 1);     cursor.close();      cursor = getactivity().getcontentresolver().query(             android.provider.mediastore.images.media.external_content_uri,             null, mediastore.images.media._id + " = ? ", new string[]{document_id}, null);     cursor.movetofirst();     string path = cursor.getstring(cursor.getcolumnindex(mediastore.images.media.data));     cursor.close();      return path; } 

logcat:

08-20 23:23:53.320 11022-11022/com.example.lupitagarcia.yosoyvallarta e/androidruntime: fatal exception: main                                                                                     process: com.example.lupitagarcia.yosoyvallarta, pid: 11022                                                                                     java.lang.nullpointerexception: attempt invoke interface method 'boolean android.database.cursor.movetofirst()' on null object reference                                                                                         @ com.example.lupitagarcia.yosoyvallarta.terminosyc.getpath(terminosyc.java:579)                                                                                         @ com.example.lupitagarcia.yosoyvallarta.terminosyc$1.onclick(terminosyc.java:355)                                                                                         @ android.view.view.performclick(view.java:5721)                                                                                         @ android.widget.textview.performclick(textview.java:10936)                                                                                         @ android.view.view$performclick.run(view.java:22620)                                                                                         @ android.os.handler.handlecallback(handler.java:739)                                                                                         @ android.os.handler.dispatchmessage(handler.java:95)                                                                                         @ android.os.looper.loop(looper.java:148)                                                                                         @ android.app.activitythread.main(activitythread.java:7406)                                                                                         @ java.lang.reflect.method.invoke(native method)                                                                                         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230)                                                                                         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)  

seems no efforts! anyway try

if(mcursor!=null && mcursor.getcount()>0 ){     mcursor.movetofirst(); } 

the reason #uri ,as getting null value there. first make sure getting proper image uri or not!


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -