Android消费者抛出没有找到类定义

时间:2017-03-24 22:44:58

标签: java android android-studio java-8 noclassdeffounderror

我在 new android studio 2.3项目中有以下代码。我有1.8和插孔启用(见下面的构建文件)。这是我添加的唯一代码:

    Consumer<Integer> consumer=new Consumer<Integer>() { // throws here a: java.lang.NoClassDefFoundError: acme.consumer.MainActivity$2
        @Override
        public void accept(Integer integer) {
            System.out.println("integer: "+integer);
        }
    };
consumer.accept(1);

似乎这应该有效。有没有人有任何想法?

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "acme.cb2"
        minSdkVersion 22
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
       }
    }
    dexOptions {
        javaMaxHeapSize "4G"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    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:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
}

1 个答案:

答案 0 :(得分:0)

消费者是在API 24中引入的 - 你有minSdkVersion 22