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

时间:2016-08-29 10:08:26

标签: android android-studio

我正在尝试使用此AsyncTask将图像上传到ftp服务器:

Child

但是,我收到主题错误。这是我的傻瓜:

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) {

 }

}

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

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()
}

P.S,这个AsyncTask之前工作得很好。但突然它停止工作告诉这个错误。我想我做了一些与其他事情发生冲突的事情! 问题是,因为我完成了这部分,我在我的应用程序上做了很多事情,我不知道哪一个可以导致它! 我看过类似的主题,但没有帮助我。 任何暗示都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

我认为你在构建文件中遗漏了这个

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

制作项目中包含的apache公共文件