I am using the following code to Upload a file to an FTP server from my android device
TextView text;
FTPClient con;
BufferedInputStream buffIn;
public class FTPFileUpload extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
con = new FTPClient();
if (params[0] != null & params[1] != null & params[2] != null & params[3] != null & params[4] != null & params[5] != null)
{
try {
con.connect(InetAddress.getByName(params[0]));
if (con.login(params[1], params[2])){
con.changeWorkingDirectory(params[3]);
con.setFileType(FTP.BINARY_FILE_TYPE);
buffIn = new BufferedInputStream(new FileInputStream(params[4]));
con.enterLocalPassiveMode();
con.storeFile(params[5], buffIn);
text.setText("upload result: successful");
}
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
try {
con.logout();
con.disconnect();
} catch (IOException E) {
Toast.makeText(getBaseContext(), E.getMessage(),Toast.LENGTH_SHORT).show();
}
}
return null;
}
}`
which is called inonCreate()
method by new FTPClient(args);
The libraries that i am using are as following
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
But the logcat shows me the error that it couldn't find a class
07-06 16:17:58.665: D/jdwp(18069): sendBufferedRequest : len=0x3B
07-06 16:17:58.674: W/asset(18069): AssetManager-->addDefaultAssets CIP path not exsit!
07-06 16:17:58.829: E/dalvikvm(18069): Could not find class 'org.apache.commons.net.ftp.FTPClient', referenced from method com.example.test.MainActivity$FTPFileUpload.doInBackground
07-06 16:17:58.829: W/dalvikvm(18069): VFY: unable to resolve new-instance 1120 (Lorg/apache/commons/net/ftp/FTPClient;) in Lcom/example/test/MainActivity$FTPFileUpload;
07-06 16:17:58.829: D/dalvikvm(18069): VFY: replacing opcode 0x22 at 0x0007
07-06 16:17:58.830: D/dalvikvm(18069): DexOpt: unable to opt direct call 0x21f8 at 0x09 in Lcom/example/test/MainActivity$FTPFileUpload;.doInBackground
07-06 16:17:58.840: V/PhoneWindow(18069): DecorView setVisiblity: visibility = 4
07-06 16:17:58.875: W/dalvikvm(18069): threadid=11: thread exiting with uncaught exception (group=0x41e739a8)
07-06 16:17:58.881: V/PhoneWindow(18069): DecorView setVisiblity: visibility = 0
07-06 16:17:58.936: E/AndroidRuntime(18069): FATAL EXCEPTION: AsyncTask #1
07-06 16:17:58.936: E/AndroidRuntime(18069): java.lang.RuntimeException: An error occured while executing doInBackground()
07-06 16:17:58.936: E/AndroidRuntime(18069): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
07-06 16:17:58.936: E/AndroidRuntime(18069): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.lang.Thread.run(Thread.java:838)
07-06 16:17:58.936: E/AndroidRuntime(18069): Caused by: java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
07-06 16:17:58.936: E/AndroidRuntime(18069): at com.example.test.MainActivity$FTPFileUpload.doInBackground(MainActivity.java:27)
07-06 16:17:58.936: E/AndroidRuntime(18069): at com.example.test.MainActivity$FTPFileUpload.doInBackground(MainActivity.java:1)
07-06 16:17:58.936: E/AndroidRuntime(18069): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-06 16:17:58.936: E/AndroidRuntime(18069): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-06 16:17:58.936: E/AndroidRuntime(18069): ... 4 more
07-06 16:17:58.993: D/libEGL(18069): loaded /system/lib/egl/libEGL_mali.so
07-06 16:17:59.010: D/libEGL(18069): loaded /system/lib/egl/libGLESv1_CM_mali.so
07-06 16:17:59.013: D/libEGL(18069): loaded /system/lib/egl/libGLESv2_mali.so
07-06 16:17:59.129: D/OpenGLRenderer(18069): Enabling debug mode 0
07-06 16:17:59.133: V/InputMethodManager(18069): onWindowFocus: null softInputMode=288 first=true flags=#1810100
07-06 16:17:59.137: V/InputMethodManager(18069): START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{423e67a8 V.E..... R.....ID 0,0-480,800} ic=null tba=android.view.inputmethod.EditorInfo@4240b780 controlFlags=#104
07-06 16:17:59.182: V/InputMethodManager(18069): Starting input: Bind result=InputBindResult{null com.android.inputmethod.latin/.LatinIME #27}
07-06 16:17:59.461: I/InputMethodManager(18069): handleMessage: MSG_SET_ACTIVE true, was false
07-06 16:17:59.971: D/OpenGLRenderer(18069): Flushing caches (mode 0)
07-06 16:18:00.020: D/OpenGLRenderer(18069): Flushing caches (mode 1)
07-06 16:18:00.038: D/OpenGLRenderer(18069): Flushing caches (mode 0)
I have fixed the NULLPOINTException and all but this just does not seem to be removed. Any suggestions to what i can do?