0

我想使用 FTP 协议将图像文件从我的 android 设备的存储卡上传到我的主机服务器。但在测试运行期间,我得到一个我无法解决的错误。期待人们帮助我。

源代码

public class FTP extends Activity implements OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ftp);
    Button upload=(Button)findViewById(R.id.button1);
    upload.setOnClickListener(this);
}
public void goforIt(){


    FTPClient con = null;

    try
    {
        con = new FTPClient();
        con.connect("longvan.webatu.com");

        if (con.login("a4602996", "25251325thanhtung"))
        {
            con.enterLocalPassiveMode(); // important!
            con.setFileType(FTPClient.BINARY_FILE_TYPE);
            String data = "/sdcard/paint/takeshi.jpg";

            FileInputStream in = new FileInputStream(new File(data));
            boolean result = con.storeFile("/paint/takeshi.jpg", in);
            in.close();
            if (result) Log.v("upload result", "succeeded");
            con.logout();
            con.disconnect();
            Toast.makeText(this, "Tai len thanh cong!", Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(this, "Ket noi that bai!", Toast.LENGTH_LONG).show();
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch (arg0.getId()) {
        case R.id.button1:
            goforIt();

            break;

        default:
            break;
    }
}  
}

错误日志

12-28 16:35:04.039: E/AndroidRuntime(11942): java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
12-28 16:35:04.039: E/AndroidRuntime(11942):    at com.example.ftp.FTP.goforIt(FTP.java:31)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at com.example.ftp.FTP.onClick(FTP.java:64)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at android.view.View.performClick(View.java:3558)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at android.view.View$PerformClick.run(View.java:14157)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at android.os.Handler.handleCallback(Handler.java:605)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at android.os.Looper.loop(Looper.java:137)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at android.app.ActivityThread.main(ActivityThread.java:4514)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at java.lang.reflect.Method.invokeNative(Native Method)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at java.lang.reflect.Method.invoke(Method.java:511)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
12-28 16:35:04.039: E/AndroidRuntime(11942):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

2

请确保您确实在项目库中添加了 jar FtpClient

于 2012-12-28T09:47:23.377 回答
0

检查您是否执行了以下操作。

  1. 检查您是否已配置构建路径
  2. 添加了 ftpclient.jar
  3. 如果您有任何疑问,请查看android_client_config 教程
于 2012-12-28T10:15:52.053 回答