gpt4 book ai didi

java - 使用 org.apache.commons.net.ftp.FTPClient 从 AsyncTask 类登录 FTP 时出错

转载 作者:行者123 更新时间:2023-12-02 05:06:49 24 4
gpt4 key购买 nike

我正在使用 AsyncTask 登录 ftp 帐户,但我不断收到此错误,

12-31 15:26:19.637: E/dalvikvm(5986): Could not find class 'org.apache.commons.net.ftp.FTPClient', referenced from method com.example.testme.Processing.connnectingwithFTP

我可以理解,我在 Asynctask 中的方法无法找到 FTPClient 类,即使它导入得很好。但我不知道如何让我的内部 AsyncTask 方法找到 FTPClient 类。

这是我的代码,

AsyncTask 类

class Processing extends AsyncTask<Object, Void, Void> {

@Override
protected Void doInBackground(Object... params) {
connnectingwithFTP("host", "username",
"password");
return null;
}

public void connnectingwithFTP(String ip, String userName, String pass) {
boolean status = false;
try {
FTPClient mFtpClient = new FTPClient();

mFtpClient.setConnectTimeout(10 * 1000);
mFtpClient.connect(InetAddress.getByName(ip));
status = mFtpClient.login(userName, pass);
Log.e("isFTPConnected", String.valueOf(status));
if (FTPReply.isPositiveCompletion(mFtpClient.getReplyCode())) {
mFtpClient.setFileType(FTP.ASCII_FILE_TYPE);
mFtpClient.enterLocalPassiveMode();
FTPFile[] mFileArray = mFtpClient.listFiles();
Log.e("Size", String.valueOf(mFileArray.length));
}
} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

这就是我在 onCreate 方法中所做的,

Processing p1 = new Processing();
p1.execute();

最佳答案

您应该将 jar 文件添加到项目的 libs 文件夹中。另外,请确保在Order and Export 选项卡下选中它。

关于java - 使用 org.apache.commons.net.ftp.FTPClient 从 AsyncTask 类登录 FTP 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27719927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com