android - File to inputStream for FTP upload returns NullPointerExeption -
i'm trying upload file ftp have trouble inputstream. returns java.lang.nullpointerexception.
how load file inputsteam?
also no progress reports. onprogressupdate never executed, why?
my code
private class asyncftp extends asynctask<string, string, string>{ @override protected string doinbackground(string... params) { publishprogress("entro"); //creo ftpclient ftpclient ftp = new ftpclient(); //defino datos del servidor string ftp_host = "not real ip"; string ftp_user = "not real user"; string ftp_pass = "not real pass"; //cargo el archivo file file = new file("/data/data/com.lstupenengo.mysql/files/xx.xx"); fileinputstream fis = null; try { fis = new fileinputstream(file); } catch (filenotfoundexception e) { e.printstacktrace(); } publishprogress("file "); //conectar try{ publishprogress("conectando"); ftp.connect(ftp_host, 21); ftp.login(ftp_user, ftp_pass); publishprogress("conecto " + string.valueof(ftp.getreplycode())); ftp.type(ftpclient.binary_file_type); //directorio ftp.changeworkingdirectory("/public_html/"); publishprogress("directorio"+string.valueof(ftp.getreplycode())); ftp.enterlocalpassivemode(); ftp.storefile("xx.xx",fis); publishprogress("subio "+string.valueof(ftp.getreplycode())); } catch (ioexception e) { e.printstacktrace(); } return null; } protected void onprogressupdate(string txt) { tv.settext(tv.gettext()+"\n"+txt); } @override protected void onpostexecute(string result){ tv.settext(tv.gettext()+"\n termino ftp"); } }
logcat
opengl es shader compiler version: 17.01.12.spl build date: 07/01/14 tue local branch: remote branch: quic/kk_2.7_rb1.41 local patches: none reconstruct branch: au_linux_android_kk_2.7_rb1.04.04.04.007.064 + nothing 12-16 08:12:46.964 9262-9262/com.lstupenengo.mysql d/openglrenderer﹕ enabling debug mode 0 12-16 08:12:47.084 9262-9262/com.lstupenengo.mysql i/activitymanager﹕ timeline: activity_idle id: android.os.binderproxy@44bd9f08 time:324929151 12-16 08:12:55.142 9262-9262/com.lstupenengo.mysql w/iinputconnectionwrapper﹕ showstatusicon on inactive inputconnection 12-16 08:12:57.344 9262-9400/com.lstupenengo.mysql i/roottools v3.1﹕ [rw, seclabel, nosuid, nodev, relatime, discard, noauto_da_alloc, data=ordered] , rw 12-16 08:12:57.534 9262-9262/com.lstupenengo.mysql i/activitymanager﹕ timeline: activity_idle id: android.os.binderproxy@44bd9f08 time:324939608 12-16 08:12:57.885 9262-9400/com.lstupenengo.mysql i/roottools v3.1﹕ [rw, seclabel, nosuid, nodev, relatime, discard, noauto_da_alloc, data=ordered] , ro 12-16 08:12:57.995 9262-9400/com.lstupenengo.mysql i/roottools v3.1﹕ [rw, seclabel, nosuid, nodev, relatime, discard, noauto_da_alloc, data=ordered] , rw 12-16 08:12:58.115 9262-9400/com.lstupenengo.mysql i/roottools v3.1﹕ [rw, relatime] , rw 12-16 08:12:58.215 9262-9400/com.lstupenengo.mysql i/roottools v3.1﹕ [ro, relatime] , ro 12-16 08:12:58.756 9262-9400/com.lstupenengo.mysql i/roottools v3.1﹕ [rw, seclabel, nosuid, nodev, relatime, discard, noauto_da_alloc, data=ordered] , ro 12-16 08:12:58.776 9262-9400/com.lstupenengo.mysql w/system.err﹕ java.io.filenotfoundexception: /data/data/com.lstupenengo.mysql/files/wa.db: open failed: eacces (permission denied) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ libcore.io.iobridge.open(iobridge.java:418) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ java.io.fileinputstream.<init>(fileinputstream.java:78) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ com.lstupenengo.mysql.mainactivity$asyncftp.doinbackground(mainactivity.java:97) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ com.lstupenengo.mysql.mainactivity$asyncftp.doinbackground(mainactivity.java:76) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ android.os.asynctask$2.call(asynctask.java:288) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ java.util.concurrent.futuretask.run(futuretask.java:237) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ java.lang.thread.run(thread.java:841) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ caused by: libcore.io.errnoexception: open failed: eacces (permission denied) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ libcore.io.posix.open(native method) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ libcore.io.blockguardos.open(blockguardos.java:110) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ @ libcore.io.iobridge.open(iobridge.java:402) 12-16 08:12:58.786 9262-9400/com.lstupenengo.mysql w/system.err﹕ ... 9 more 12-16 08:13:00.577 9262-9400/com.lstupenengo.mysql w/dalvikvm﹕ threadid=15: thread exiting uncaught exception (group=0x41a32d88) 12-16 08:13:00.587 9262-9400/com.lstupenengo.mysql e/androidruntime﹕ fatal exception: asynctask #5 process: com.lstupenengo.mysql, pid: 9262 java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:300) @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) @ java.util.concurrent.futuretask.setexception(futuretask.java:222) @ java.util.concurrent.futuretask.run(futuretask.java:242) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:841) caused by: java.lang.nullpointerexception @ org.apache.commons.net.io.util.copystream(util.java:100) @ org.apache.commons.net.ftp.ftpclient._storefile(ftpclient.java:653) @ org.apache.commons.net.ftp.ftpclient.__storefile(ftpclient.java:624) @ org.apache.commons.net.ftp.ftpclient.storefile(ftpclient.java:1976) @ com.lstupenengo.mysql.mainactivity$asyncftp.doinbackground(mainactivity.java:117) @ com.lstupenengo.mysql.mainactivity$asyncftp.doinbackground(mainactivity.java:76) @ android.os.asynctask$2.call(asynctask.java:288) @ java.util.concurrent.futuretask.run(futuretask.java:237) at android.os.asynctask$serialexecutor$1.run(asynctask.java:231) at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) at java.lang.thread.run(thread.java:841)
your onprogressupdate doesn't override, needs parameter (params... param) , not single string.
this definition.
protected void onprogressupdate (progress... values)
so need
protected void onprogressupdate (string... values)
and string values[0] if put 1 string parameter in publishprogress.
by other hand, exception, it's hard without stacktrace check if fis null before storing file. nullpointers easy fix. anyway have small tutorial here
Comments
Post a Comment