image - Take a Picture or Take from Gallery with Custom Dialog in Android -


i making dialogue able upload pictures of captured images, or selected gallery. but, when it's done crop image, application force close. here method developed:

 public void uploadpo() {     ivimage1 = (imageview) findviewbyid(r.id.iv_image1);     etimage1 = (edittext) findviewbyid(r.id.et_image1);     ivimage2 = (imageview) findviewbyid(r.id.iv_image2);     etimage2 = (edittext) findviewbyid(r.id.et_image2);     ivimage3 = (imageview) findviewbyid(r.id.iv_image3);     etimage3 = (edittext) findviewbyid(r.id.et_image3);     ivimage4 = (imageview) findviewbyid(r.id.iv_image4);     etimage4 = (edittext) findviewbyid(r.id.et_image4);      final dialog d = new dialog(transdetailactivity.this);     d.requestwindowfeature(window.feature_no_title);     d.getwindow().setbackgrounddrawable(new colordrawable((color.transparent)));     d.setcontentview(r.layout.upload_po);     final framelayout takepicture = (framelayout) d.findviewbyid(r.id.ambil_gambar);     final framelayout pilihgambar = (framelayout) d.findviewbyid(r.id.pilih_di_gallery);     final framelayout batal = (framelayout) d.findviewbyid(r.id.batal);     final framelayout ok = (framelayout) d.findviewbyid(r.id.ok);     takepicture.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             selectfrom(pick_from_camera);         }     });     pilihgambar.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             selectfrom(pick_from_gallery);         }     });     batal.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             d.dismiss();         }     });     ok.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             labelimage1 = etimage1.gettext().tostring();             labelimage2 = etimage1.gettext().tostring();             labelimage3 = etimage1.gettext().tostring();             labelimage4 = etimage1.gettext().tostring();              if (ivimage1 == null || ivimage2 == null || ivimage3 == null || ivimage4 == null) {                 toast.maketext(getapplicationcontext(), "masukkan empat gambar", toast.length_short).show();             } else if (labelimage1.trim().equals("") || labelimage2.trim().equals("") || labelimage3.trim().equals("") || labelimage4.trim().equals("")) {                 toast.maketext(getapplicationcontext(), "masukkan label pada setiap gambar", toast.length_short).show();             } else {                 uploadtoapi();             }         }     });     d.show(); }  private void selectfrom(int from) {     if (from == pick_from_camera) {         intent intent = new intent(mediastore.action_image_capture);         file dir = environment.getexternalstoragepublicdirectory(environment.directory_dcim);         file output = new file(dir, "avatar" + string.valueof(system.currenttimemillis()) + ".jpeg");         mimagecaptureuri = uri.fromfile(output);         intent.putextra(mediastore.extra_output, mimagecaptureuri);         intent.putextra(mediastore.extra_output, uri.fromfile(output));         try {             intent.putextra("return-data", true);             startactivityforresult(intent, from);         } catch (activitynotfoundexception e) {             e.printstacktrace();         }     } else {         if (build.version.sdk_int < 19) {             intent intent = new intent();             intent.settype("image/*");             intent.setaction(intent.action_get_content);             startactivityforresult(intent.createchooser(intent, "complete action using"), from);         } else {             intent intent = new intent();             intent.settype("image/*");             intent.setaction(intent.action_pick);             startactivityforresult(intent.createchooser(intent, "complete action using"), from);         }     } }  private void docrop() {     intent intent = new intent("com.android.camera.action.crop");     intent.settype("image/*");     list<resolveinfo> list = getpackagemanager().queryintentactivities(intent, 0);     int size = list.size();     if (size == 0) {         toast.maketext(getapplicationcontext(), "can not find image crop app", toast.length_short).show();         intent.setdata(mimagecaptureuri);         intent.putextra("return-data", true);         intent.putextra("aspectx", 1);         intent.putextra("aspecty", 1);         intent.putextra("crop", "true");         intent.putextra("outputx", 256);         intent.putextra("outputy", 256);         startactivityforresult(intent, crop_from_camera);         return;     } else {         intent.setdata(mimagecaptureuri);         intent.putextra("aspectx", 1);         intent.putextra("aspecty", 1);         intent.putextra("outputx", 256);         intent.putextra("outputy", 256);         intent.putextra("crop", "true");         intent.putextra("return-data", true);         resolveinfo res = list.get(0);         intent.setcomponent(new componentname(res.activityinfo.packagename, res.activityinfo.name));         startactivityforresult(intent, crop_from_camera);     } }   @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     //toast.maketext(getactivity(),""+resultcode+"", toast.length_short).show();     if (data != null) {         if (requestcode == pick_from_camera) {             docrop();         } else if (requestcode == pick_from_gallery) {             mimagecaptureuri = data.getdata();             docrop();         } else if (requestcode == crop_from_camera) {             bundle extras = data.getextras();             if (extras != null) {                 bitmap photo = extras.getparcelable("data");                 /*picasso.with(this)                         .load()                         .transform(new circletransform())                         .into(imageprofile);*/                  if (statusonupload == 1) {                     ivimage1.setimagebitmap(photo);                 } else if (statusonupload == 2) {                     ivimage2.setimagebitmap(photo);                 } else if (statusonupload == 3) {                     ivimage3.setimagebitmap(photo);                 } else if (statusonupload == 4) {                     ivimage4.setimagebitmap(photo);                 }                   bytearrayoutputstream baos = new bytearrayoutputstream();                 photo.compress(bitmap.compressformat.jpeg, 80, baos);                 byte[] b = baos.tobytearray();                  if (statusonupload == 1) {                     encodedimagestring1 = base64.encodetostring(b, base64.no_wrap);                     log.d(tag, encodedimagestring1.tostring());                 } else if (statusonupload == 2) {                     encodedimagestring2 = base64.encodetostring(b, base64.no_wrap);                 } else if (statusonupload == 3) {                     encodedimagestring3 = base64.encodetostring(b, base64.no_wrap);                 } else if (statusonupload == 4) {                     encodedimagestring4 = base64.encodetostring(b, base64.no_wrap);                 }                  //log.i("")                  //toast.maketext(getapplicationcontext(),""+encodedimagestring+"",toast.length_short).show();                 //dialogdeal dialogdeal=new dialogdeal(editprofileactivity.this,"imagebase64",encodedimagestring,"cancel");                 //dialogdeal.show();              } else { //logmanager.logi("extras == null");}}}} 

this layout:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/corner_white">  <textview     android:id="@+id/tittle"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerhorizontal="true"     android:layout_margintop="20dp"     android:text="upload purchase order"     android:textappearance="?android:attr/textappearancemedium"     android:textcolor="@color/blue" />  <view     android:id="@+id/line"     android:layout_width="match_parent"     android:layout_height="2dp"     android:layout_below="@+id/tittle"     android:layout_margintop="20dp"     android:background="@color/blue" />  <linearlayout     android:id="@+id/menu_upload"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_below="@id/line"     android:orientation="horizontal">      <framelayout         android:id="@+id/ambil_gambar"         android:layout_width="match_parent"         android:layout_height="50dp"         android:layout_weight="1">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerhorizontal="true"             android:layout_gravity="center"             android:text="ambil gambar"             android:textappearance="?android:attr/textappearancesmall" />     </framelayout>      <view         android:id="@+id/line2"         android:layout_width="2dp"         android:layout_height="match_parent"         android:layout_below="@+id/depan"         android:background="@color/grey" />      <framelayout         android:id="@+id/pilih_di_gallery"         android:layout_width="match_parent"         android:layout_height="50dp"         android:layout_weight="1">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:text="pilih di gallery"             android:textappearance="?android:attr/textappearancesmall" />/>     </framelayout> </linearlayout>  <view     android:id="@+id/line3"     android:layout_width="match_parent"     android:layout_height="2dp"     android:layout_below="@id/menu_upload"     android:background="@color/blue" />  <tablelayout     android:id="@+id/gambar_upload"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_below="@id/line3"     android:shrinkcolumns="*"     android:stretchcolumns="*"     android:columncount="2"     android:rowcount="2">      <tablerow         android:layout_width="match_parent"         android:layout_height="wrap_content">          <relativelayout             android:id="@+id/rl_image1"             android:layout_width="wrap_content"             android:layout_height="wrap_content">              <imageview                 android:id="@+id/iv_image1"                 android:layout_width="180dp"                 android:layout_height="120dp"                 android:layout_marginbottom="5dp"                 android:layout_marginleft="10dp"                 android:layout_margintop="5dp"                 android:layout_marginright="10dp"                 android:src="@mipmap/addmorepicture"                 android:layout_gravity="left|center_vertical" />              <framelayout                 android:layout_width="match_parent"                 android:layout_height="40dp"                 android:background="#809e9e9e"                 android:layout_alignbottom="@id/iv_image1"                 android:layout_alignleft="@id/iv_image1"                 android:layout_alignstart="@id/iv_image1"                 android:layout_alignright="@id/iv_image1"                 android:layout_alignend="@id/iv_image1"                 android:layout_gravity="center_horizontal|bottom">                  <edittext                     android:id="@id/et_image1"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center"                     android:hint="label image 1"                     android:textappearance="?android:attr/textappearancesmall"/>             </framelayout>         </relativelayout>          <relativelayout             android:id="@+id/rl_image2"             android:visibility="gone"             android:layout_width="wrap_content"             android:layout_height="wrap_content">              <imageview                 android:id="@+id/iv_image2"                 android:layout_width="180dp"                 android:layout_height="120dp"                 android:layout_marginbottom="5dp"                 android:layout_marginleft="10dp"                 android:layout_margintop="5dp"                 android:layout_marginright="10dp"                 android:src="@mipmap/addmorepicture" />              <framelayout                 android:layout_width="match_parent"                 android:layout_height="40dp"                 android:background="#809e9e9e"                 android:layout_alignbottom="@id/iv_image2"                 android:layout_alignleft="@id/iv_image2"                 android:layout_alignstart="@id/iv_image2"                 android:layout_alignright="@id/iv_image2"                 android:layout_alignend="@id/iv_image2">                  <edittext                     android:id="@id/et_image2"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center"                     android:hint="label image 2"                     android:textappearance="?android:attr/textappearancesmall"/>             </framelayout>         </relativelayout>     </tablerow>      <tablerow         android:layout_width="match_parent"         android:layout_height="wrap_content">          <relativelayout             android:id="@+id/rl_image3"             android:visibility="gone"             android:layout_width="wrap_content"             android:layout_height="wrap_content">              <imageview                 android:id="@+id/iv_image3"                 android:layout_width="180dp"                 android:layout_height="120dp"                 android:layout_marginbottom="5dp"                 android:layout_marginleft="10dp"                 android:layout_margintop="5dp"                 android:layout_marginright="10dp"                 android:src="@mipmap/addmorepicture"                 android:layout_gravity="left|center_vertical" />              <framelayout                 android:layout_width="match_parent"                 android:layout_height="40dp"                 android:background="#809e9e9e"                 android:layout_alignbottom="@id/iv_image3"                 android:layout_alignleft="@+id/iv_image3"                 android:layout_alignstart="@+id/iv_image3"                 android:layout_alignright="@+id/iv_image3"                 android:layout_alignend="@+id/iv_image3"                 android:layout_gravity="center_horizontal|bottom">                  <edittext                     android:id="@id/et_image3"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center"                     android:hint="label image 3"                     android:textappearance="?android:attr/textappearancesmall"/>             </framelayout>         </relativelayout>          <relativelayout             android:id="@+id/rl_image4"             android:visibility="gone"             android:layout_width="wrap_content"             android:layout_height="wrap_content">              <imageview                 android:id="@+id/iv_image4"                 android:layout_width="180dp"                 android:layout_height="120dp"                 android:layout_marginbottom="5dp"                 android:layout_marginleft="10dp"                 android:layout_margintop="5dp"                 android:layout_marginright="10dp"                 android:src="@mipmap/addmorepicture" />              <framelayout                 android:layout_width="match_parent"                 android:layout_height="40dp"                 android:background="#809e9e9e"                 android:layout_alignbottom="@id/iv_image4"                 android:layout_alignleft="@id/iv_image4"                 android:layout_alignstart="@id/iv_image4"                 android:layout_alignright="@id/iv_image4"                 android:layout_alignend="@id/iv_image4">                  <edittext                     android:id="@id/et_image3"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center"                     android:hint="label image 3"                     android:textappearance="?android:attr/textappearancesmall"/>             </framelayout>         </relativelayout>     </tablerow> </tablelayout>  <view     android:id="@+id/line4"     android:layout_width="match_parent"     android:layout_height="2dp"     android:layout_below="@+id/gambar_upload"     android:background="@color/blue" />  <linearlayout     android:id="@+id/aksi"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_below="@id/line4"     android:orientation="horizontal">      <framelayout         android:id="@+id/batal"         android:layout_width="match_parent"         android:layout_height="50dp"         android:layout_weight="1">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerhorizontal="true"             android:layout_gravity="center"             android:text="batal"             android:textappearance="?android:attr/textappearancesmall" />     </framelayout>      <view         android:id="@+id/line5"         android:layout_width="2dp"         android:layout_height="match_parent"         android:layout_below="@+id/depan"         android:background="@color/grey" />      <framelayout         android:id="@+id/ok"         android:layout_width="match_parent"         android:layout_height="50dp"         android:layout_weight="1">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:text="ok"             android:textappearance="?android:attr/textappearancesmall" />/>     </framelayout> </linearlayout> 

then, sign of error:

 02-06 11:01:34.836 11791-11791/blablabla.wkwk e/androidruntime: fatal exception: main    java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=3, result=-1, data=intent { (has extras) }} activity {blablabla.wkwk/codelabs.baf.transdetailactivity}: java.lang.nullpointerexception   @ android.app.activitythread.deliverresults(activitythread.java:3488)   @ android.app.activitythread.handlesendresult(activitythread.java:3531)   @ android.app.activitythread.access$1100(activitythread.java:156)   @ android.app.activitythread$h.handlemessage(activitythread.java:1388)   @ android.os.handler.dispatchmessage(handler.java:99)   @ android.os.looper.loop(looper.java:153)   @ android.app.activitythread.main(activitythread.java:5299)   @ java.lang.reflect.method.invokenative(native method)   @ java.lang.reflect.method.invoke(method.java:511)   @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833)   @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600)   @ dalvik.system.nativestart.main(native method)   caused by: java.lang.nullpointerexception   @ blablabla.wkwk.transdetailactivity.onactivityresult(transdetailactivity.java:531)   @ android.app.activity.dispatchactivityresult(activity.java:5371)   @ android.app.activitythread.deliverresults(activitythread.java:3484)   @ android.app.activitythread.handlesendresult(activitythread.java:3531)    @ android.app.activitythread.access$1100(activitythread.java:156)    @ android.app.activitythread$h.handlemessage(activitythread.java:1388)    @ android.os.handler.dispatchmessage(handler.java:99)    @ android.os.looper.loop(looper.java:153)    @ android.app.activitythread.main(activitythread.java:5299)    @ java.lang.reflect.method.invokenative(native method)    @ java.lang.reflect.method.invoke(method.java:511)    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833)    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600)    @ dalvik.system.nativestart.main(native method) 

for note, remake methode class wihtout dialog , work. able me?

it looks need call findviewbyid() on dialog, , put calls after call d.setcontentview():

 public void uploadpo() {      final dialog d = new dialog(transdetailactivity.this);     d.requestwindowfeature(window.feature_no_title);     d.getwindow().setbackgrounddrawable(new colordrawable((color.transparent)));     d.setcontentview(r.layout.upload_po);     final framelayout takepicture = (framelayout) d.findviewbyid(r.id.ambil_gambar);     final framelayout pilihgambar = (framelayout) d.findviewbyid(r.id.pilih_di_gallery);     final framelayout batal = (framelayout) d.findviewbyid(r.id.batal);     final framelayout ok = (framelayout) d.findviewbyid(r.id.ok);      ivimage1 = (imageview) d.findviewbyid(r.id.iv_image1);     etimage1 = (edittext) d.findviewbyid(r.id.et_image1);     ivimage2 = (imageview) d.findviewbyid(r.id.iv_image2);     etimage2 = (edittext) d.findviewbyid(r.id.et_image2);     ivimage3 = (imageview) d.findviewbyid(r.id.iv_image3);     etimage3 = (edittext) d.findviewbyid(r.id.et_image3);     ivimage4 = (imageview) d.findviewbyid(r.id.iv_image4);     etimage4 = (edittext) d.findviewbyid(r.id.et_image4);     //........................ 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -