首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient

java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
EN

Stack Overflow用户
提问于 2016-08-29 10:08:25
回答 1查看 3K关注 0票数 1

我试图使用这个AsyncTask将图像上传到ftp服务器:

代码语言:javascript
复制
import android.content.Context;
import android.os.AsyncTask;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import java.io.FileInputStream;

public class my_ftp_uploader extends AsyncTask<String, Void, String> {

public String file_name;
private Context context;
public FTPClient mFTPClient = null;

public my_ftp_uploader(Context context) {
    this.context = context;
}

protected void onPreExecute() {

}

@Override
protected String doInBackground(String... arg0) {
    String filesToUploadPath = arg0[0];
    file_name = arg0[1];

    try {
        mFTPClient = new FTPClient(); 
        mFTPClient.connect("my_domain", 21);

        if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
            boolean status = mFTPClient.login("My_Domain", "My_password");

            mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
            mFTPClient.enterLocalPassiveMode();
            try {
                FileInputStream srcFileStream = new FileInputStream(filesToUploadPath);

                try {
                    mFTPClient.changeWorkingDirectory("myServer_path");
                    status = mFTPClient.storeFile(file_name + ".jpg", srcFileStream);
                    try {
                        mFTPClient.logout();
                        mFTPClient.disconnect();
                    } catch (Exception e) {
                    }
                } catch(Exception e) {
                }

                srcFileStream.close();
            } catch (Exception e) {
            }

        }
    } catch(Exception e) {

    }

    return "done";
}

@Override
protected void onPostExecute(String result) {

 }

}

但是,我收到了主题错误。这是我的秤:

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:23.+'
        force 'com.android.support:appcompat-v7:23.+'
        force 'com.android.support:recyclerview-v7:23.+'
    }
}
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "my_app_id"
    minSdkVersion 15
    targetSdkVersion 15
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.nononsenseapps:filepicker:3.0.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.daimajia.swipelayout:library:1.2.0@aar'
compile 'net.gotev:uploadservice:3.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'net.gotev:uploadservice-ftp:3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
}

repositories {
jcenter()
}

以下的逻辑点作为错误的来源:

代码语言:javascript
复制
mFTPClient = new FTPClient();

P.S .,这个AsyncTask以前很好用。但突然之间,它停止了工作,告诉这个错误。我想我做了一些与其他事情相冲突的事情!,问题是,自从我完成了这个部分,我在我的应用程序上做了很多事情,我不知道哪一个会导致它!我曾看过类似的话题,但没有帮助我。任何提示都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-29 18:41:36

我想你在构建文件中漏掉了这个

compile group: 'commons-net', name: 'commons-net', version: '2.0'

使apache包含在项目中

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39203650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档