我正在做一个项目。我的项目第一步连接到 ftp。我阅读了文档并在 stackoverflow 中进行了搜索,但没有找到解决方案。我是 android 开发者的初学者。运行应用程序时,我在 LogCat 和 java 文件下方看到了致命错误。我该如何解决这个问题,请帮助我这个项目对我来说非常重要。
日志猫:
11-03 04:27:37.640: E/AndroidRuntime(330): FATAL EXCEPTION: main
11-03 04:27:37.640: E/AndroidRuntime(330): java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
11-03 04:27:37.640: E/AndroidRuntime(330): at com.example.cka.MainActivity$1.onClick(MainActivity.java:33)
11-03 04:27:37.640: E/AndroidRuntime(330): at android.view.View.performClick(View.java:2408)
11-03 04:27:37.640: E/AndroidRuntime(330): at android.view.View$PerformClick.run(View.java:8816)
11-03 04:27:37.640: E/AndroidRuntime(330): at android.os.Handler.handleCallback(Handler.java:587)
11-03 04:27:37.640: E/AndroidRuntime(330): at android.os.Handler.dispatchMessage(Handler.java:92)
11-03 04:27:37.640: E/AndroidRuntime(330): at android.os.Looper.loop(Looper.java:123)
11-03 04:27:37.640: E/AndroidRuntime(330): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-03 04:27:37.640: E/AndroidRuntime(330): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 04:27:37.640: E/AndroidRuntime(330): at java.lang.reflect.Method.invoke(Method.java:521)
11-03 04:27:37.640: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-03 04:27:37.640: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-03 04:27:37.640: E/AndroidRuntime(330): at dalvik.system.NativeStart.main(Native Method)
11-03 04:27:40.810: I/Process(330): Sending signal. PID: 330 SIG: 9
--
主要活动:
Button btn = (Button) findViewById(R.id.button1);
final TextView tv = (TextView) findViewById(R.id.textView1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
core f = new core();
f.mFTPClient = new FTPClient();
f.ftpConnect("**.***.***.**", "****", "****", 21);
try {
tv.setText(f.ftpStatus());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
--
核心.java
package com.example.cka;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.net.ftp.*;
import android.util.Log;
public class core {
private static final String TAG = null;
public FTPClient mFTPClient = null;
public boolean ftpConnect(String host, String username,String password, int port){
try {
mFTPClient = new FTPClient();
// connecting to the host
mFTPClient.connect(host, port);
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
boolean status = mFTPClient.login(username, password);
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
return status;
}
}
catch(Exception e) {
Log.d(TAG, "Error: could not connect to host " + host );
}
return false;
}
public boolean ftpDisconnect()
{
try {
mFTPClient.logout();
mFTPClient.disconnect();
return true;
} catch (Exception e) {
Log.d(TAG, "Error occurred while disconnecting from ftp server.");
}
return false;
}
public String ftpStatus() throws IOException{
String status = mFTPClient.getStatus();
return status;
}
}