java - android multiple upload image error -


i got error when tried upload of images. use "for" loop process, still got error in looping. if don't use for, still can upload image 1 image uploaded. how can solve this?

uploadactivity.java

intent intent = getintent(); filepath = intent.getstringextra("filepath");       arraylist<string> flpath = new arraylist<string>();       sharedpreferences prefs = getsharedpreferences("savedfilepathsjsonarray",             context.mode_private);     string myjsonarraystring = prefs.getstring("savedfilepathsjsonarray",             "");       if (!myjsonarraystring.isempty()) {         jsonarray jsonarray = null;         try {             jsonarray = new jsonarray(myjsonarraystring);         } catch (jsonexception e) {             // todo auto-generated catch block             e.printstacktrace();         }         (int = 0; < jsonarray.length(); i++) {             try {                 flpath.add(jsonarray.get(i).tostring());             } catch (jsonexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }         }     }        flpath.add(filepath);      jsonarray mjsonarray = new jsonarray(flpath);     sharedpreferences.editor editor = prefs.edit();     editor.putstring("savedfilepathsjsonarray", mjsonarray.tostring()).commit();        (int = 0; < flpath.size(); i++) {         imgfile = new file(flpath.get(i));         if (imgfile.exists()) {               final bitmapfactory.options options = new bitmapfactory.options();                 options.insamplesize = 8;                 bitmap mybitmap = bitmapfactory.decodefile(imgfile.getabsolutepath(),options);              imageview myimage = new imageview(this);              myimage.setmaxheight(100);              myimage.setmaxwidth(100);             myimage.setimagebitmap(mybitmap);             layout2.addview(myimage);         }     }  private class uploadfiletoserver extends asynctask<void, integer, string> {     @override     protected void onpreexecute() {         // setting progress bar 0         progressbar.setprogress(0);         super.onpreexecute();     }      @override     protected void onprogressupdate(integer... progress) {         // making progress bar visible         progressbar.setvisibility(view.visible);          // updating progress bar value         progressbar.setprogress(progress[0]);          // updating percentage value         txtpercentage.settext(string.valueof(progress[0]) + "%");     }      @override     protected string doinbackground(void... params) {         return uploadfile();     }      @suppresswarnings("deprecation")     private string uploadfile() {          string responsestring = null;         (int = 0; < flpath.size(); i++) {             file file = new file( flpath.get(i));         httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost(config.file_upload_url);          try {             androidmultipartentity entity = new androidmultipartentity(                     new progresslistener() {                          @override                         public void transferred(long num) {                             publishprogress((int) ((num / (float) totalsize) * 100));                         }                     });                // adding file data http body             entity.addpart("image", new filebody(file));              // parameters if want pass server             entity.addpart("website",                     new stringbody("www.androidhive.info"));             entity.addpart("email", new stringbody("abc@gmail.com"));              totalsize = entity.getcontentlength();             httppost.setentity(entity);              // making server call             httpresponse response = httpclient.execute(httppost);             httpentity r_entity = response.getentity();              int statuscode = response.getstatusline().getstatuscode();             if (statuscode == 200) {                 // server response                 responsestring = entityutils.tostring(r_entity);             } else {                 responsestring = "error occurred! http status code: "                         + statuscode;             }          } catch (clientprotocolexception e) {             responsestring = e.tostring();         } catch (ioexception e) {             responsestring = e.tostring();         }         }         return responsestring;      } 

config.java

public class config {  public static final string file_upload_url = "http://....";      // directory name store captured images , videos     public static final string image_directory_name = "andrd_upload";  } 

error logcat

01-27 16:23:45.940: w/dalvikvm(15986): threadid=12: thread exiting uncaught exception (group=0x40fe7438) 01-27 16:23:45.950: e/androidruntime(15986): fatal exception: asynctask #1 01-27 16:23:45.950: e/androidruntime(15986): java.lang.runtimeexception: error occured while executing doinbackground() 01-27 16:23:45.950: e/androidruntime(15986):    @ android.os.asynctask$3.done(asynctask.java:299) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.futuretask.run(futuretask.java:137) 01-27 16:23:45.950: e/androidruntime(15986):    @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.lang.thread.run(thread.java:856) 01-27 16:23:45.950: e/androidruntime(15986): caused by: java.lang.nullpointerexception 01-27 16:23:45.950: e/androidruntime(15986):    @ com.camerafileupload.uploadactivity$uploadfiletoserver.uploadfile(uploadactivity.java:228) 01-27 16:23:45.950: e/androidruntime(15986):    @ com.camerafileupload.uploadactivity$uploadfiletoserver.doinbackground(uploadactivity.java:221) 01-27 16:23:45.950: e/androidruntime(15986):    @ com.camerafileupload.uploadactivity$uploadfiletoserver.doinbackground(uploadactivity.java:1) 01-27 16:23:45.950: e/androidruntime(15986):    @ android.os.asynctask$2.call(asynctask.java:287) 01-27 16:23:45.950: e/androidruntime(15986):    @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 01-27 16:23:45.950: e/androidruntime(15986):    ... 5 more 01-27 16:23:46.130: d/hardwarerenderer(15986): draw surface valid dirty= null 01-27 16:23:46.180: d/hardwarerenderer(15986): draw surface valid dirty= null 01-27 16:23:46.220: d/hardwarerenderer(15986): draw surface valid dirty= null 01-27 16:25:29.910: d/dalvikvm(15986): wait_for_concurrent_gc blocked 0ms 01-27 16:25:29.950: d/dalvikvm(15986): gc_explicit freed 223k, 8% free 15337k/16583k, paused 2ms+4ms, total 38ms 

screenshoot

enter image description here

edit: put error logcat , screenshoot of error page (uploadactivity.java).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -