错误ClassNotFoundException:未找到类“java.lang.invoke.MethodType”

时间:2018-04-19 18:10:34

标签: java android

某些服务器返回时会出现此错误。我正在使用异步任务。我已经改为改装,但错误仍然存​​在。据我所知,我不在代码中使用lambda表达式。 我该如何解决这个错误?如果有必要,我可以把类代码。

错误:

  

引起:java.lang.ClassNotFoundException:路径上没有找到类“java.lang.invoke.MethodType”:DexPathList [[zip文件]   “/data/app/br.com.sis.app.aten-1/base.apk”,zip文件   “/data/app/br.com.sis.app.aten-1/split_lib_dependencies_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_0_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_1_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_2_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_3_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_4_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_5_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_6_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_7_apk.apk”,zip   文件“/data/app/br.com.sis.app.aten-1/split_lib_slice_8_apk.apk”,zip   文件   “/data/app/br.com.sis.app.aten-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/br.com.sis.app.aten-1/lib/arm,   / system / lib,/ vendor / lib]]

     

at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

这是我的傻瓜:

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        buildToolsVersion "27.0.3"

        defaultConfig {
            applicationId "br.com.sis.app.aten"
            minSdkVersion 16
            targetSdkVersion 27
            versionCode 1
            versionName "0.0.0.5"
            multiDexEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

        buildTypes {
            debug {
                debuggable true
            }
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                debuggable false
            }
        }
    }

    dependencies {
        implementation 'com.google.firebase:firebase-core:12.0.1'
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:27.1.0'
        compile 'com.android.support:design:27.1.0'
        compile 'com.android.support:cardview-v7:27.1.0'
        compile 'org.apache.commons:commons-lang3:3.5'
        compile 'com.detectlanguage:detectlanguage:1.0.5'
        compile 'com.google.apis:google-api-services-translate:v2-rev51-1.23.0'
        compile 'com.google.android.gms:play-services-analytics:12.0.1'
        compile 'de.hdodenhof:circleimageview:2.2.0'
        implementation project(':service_aten')
compile 'com.android.support:multidex:1.0.3'
        implementation project(':communication_service')
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    }

    apply plugin: 'com.google.gms.google-services'

app在这行asyncTask类中断:

@Override
protected void done() {
    try {
        postResultIfNotInvoked(get());
    } catch (Exception e) {
    ....
    }
}

Gson在休息前通过的方法:

public static Object parseJsonObjectToObject(JsonObject jsonObject, Object object) throws CommonsException {
    try {
        Gson gson = createGsonObject();

        String nameClass = object.getClass().getCanonicalName().toString();//CRASH!!!!!!
        Object objectParseGson = null;

        objectParseGson = createObject(nameClass);
        objectParseGson = gson.fromJson(jsonObject, object.getClass());

        return objectParseGson;

    } catch (Exception e) {
        throw new CommonsException(e.getLocalizedMessage(), e.getMessage());
    }
}

任何人都可以帮我吗?它并非在每种情况下都会中断,其他类似的项目也能顺利运行。

1 个答案:

答案 0 :(得分:0)

按照评论中的提示解决如下问题。

我有一个实例化应用程序的类:

public class MyApplicationInstance extends Application {

    private static MyApplicationInstance instanceApplication;

    private String dsChaveAcessoWbs;
    private Tracker mTracker;

    /**
     * Verificação de instancia devido uso da camera
     */
    public MyApplicationInstance() {

        if (instanceApplication == null) {
            instanceApplication = this;
        }
    }

    public static MyApplicationInstance getInstanceApplicationSingleton() {

        return instanceApplication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }
...
}

我在此课程中将Application更改为MultiDexApplication并且有效。

public class MyApplicationInstance extends MultiDexApplication {

    private static MyApplicationInstance instanceApplication;

    private String dsChaveAcessoWbs;
    private Tracker mTracker;

    /**
     * Verificação de instancia devido uso da camera
     */
    public MyApplicationInstance() {

        if (instanceApplication == null) {
            instanceApplication = this;
        }
    }

    public static MyApplicationInstance getInstanceApplicationSingleton() {

        return instanceApplication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }
...
}

我按照谷歌文档: https://developer.android.com/studio/build/multidex.html