我正在尝试使用简单的代码通过android将文件上传到FTP服务器(实际上我尝试过其中一些代码)示例是:
package com.example.testtrials;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.jibble.simpleftp.SimpleFTP;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
public class TestActivity extends Activity {
TextView text;
public class FTPFileUpload extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
SimpleFTP ftp = new SimpleFTP();
// Connect to an FTP server on port 21.
ftp.connect(params[0], 21, params[1], params[2]);
// Set binary mode.
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd(params[3]);
// You can also upload from an InputStream, e.g.
ftp.stor(new FileInputStream(new File(params[4])), params[5]);
// Quit from the FTP server.
ftp.disconnect();
text.setText("Upload Successful");
}
catch (IOException e) {
// Jibble.
}
return null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout);
text = (TextView) findViewById(R.id.text);
FTPFileUpload task = new FTPFileUpload();
task.execute("StringArguments");
}
}
但是logcat给了我以下错误:
07-10 14:34:49.500: E/dalvikvm(7700): Could not find class 'org.jibble.simpleftp.SimpleFTP', referenced from method com.example.testtrials.TestActivity$FTPFileUpload.doInBackground
07-10 14:34:49.500: W/dalvikvm(7700): VFY: unable to resolve new-instance 1262 (Lorg/jibble/simpleftp/SimpleFTP;) in Lcom/example/testtrials/TestActivity$FTPFileUpload;
07-10 14:34:49.500: D/dalvikvm(7700): VFY: replacing opcode 0x22 at 0x0000
07-10 14:34:49.500: D/dalvikvm(7700): DexOpt: unable to opt direct call 0x2564 at 0x02 in Lcom/example/testtrials/TestActivity$FTPFileUpload;.doInBackground
07-10 14:34:49.510: W/dalvikvm(7700): threadid=11: thread exiting with uncaught exception (group=0x41fa12b8)
07-10 14:34:49.510: E/AndroidRuntime(7700): FATAL EXCEPTION: AsyncTask #1
07-10 14:34:49.510: E/AndroidRuntime(7700): java.lang.RuntimeException: An error occured while executing doInBackground()
07-10 14:34:49.510: E/AndroidRuntime(7700): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-10 14:34:49.510: E/AndroidRuntime(7700): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.lang.Thread.run(Thread.java:856)
07-10 14:34:49.510: E/AndroidRuntime(7700): Caused by: java.lang.NoClassDefFoundError: org.jibble.simpleftp.SimpleFTP
07-10 14:34:49.510: E/AndroidRuntime(7700): at com.example.testtrials.TestActivity$FTPFileUpload.doInBackground(TestActivity.java:23)
07-10 14:34:49.510: E/AndroidRuntime(7700): at com.example.testtrials.TestActivity$FTPFileUpload.doInBackground(TestActivity.java:1)
07-10 14:34:49.510: E/AndroidRuntime(7700): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-10 14:34:49.510: E/AndroidRuntime(7700): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-10 14:34:49.510: E/AndroidRuntime(7700): ... 5 more
我尝试过以下方法:
project -> build path -> Add External Jars...
也project -> properties -> Java Build Path -> Order & Export -> (All are checked)
以及project -> Android Tools -> Fix Project Properties
我也试过了commons.net 3.3
,但我得到了同样的错误。我重启了我的系统,没用。重新载入jar files
,但徒劳无功。即使重新安装IDE及其所有包装,但似乎没有任何作用。请帮忙吗?