【问题标题】:Failed to instantiate one or more classes error in android studio because of which the design isn't displayed无法在 android studio 中实例化一个或多个类错误,因为没有显示设计
【发布时间】:2019-11-29 00:33:02
【问题描述】:

我在 android studio 中的布局出现问题,由于名为“无法实例化一个或多个类”的错误而无法显示。我的 build.gradle 应用程序模块文件也出现错误,其错误消息如下所示。

我是 android studio 的新手,我尽我所能,但我似乎一无所获。如果您有解决方案,请告诉我。

  • 我尝试在 build.gradle 应用程序模块中将我的 compileSdkVersion 和 targetSdkVersion 更改为较低版本,即从 28 更改为 26,但不起作用。

  • 我也尝试过清理项目,然后使项目失效/重新启动。

  • 我也尝试过重建项目。

我的 gradle 文件:

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

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "naik.dattaraj.meme2"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        //exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0' // This line shows the below mentioned error message
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
    implementation 'com.firebase:firebase-client-android:2.5.2'
    implementation 'com.google.firebase:firebase-database:18.0.0'
    implementation 'com.firebaseui:firebase-ui-database:2.1.0'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.firebase:firebase-storage:18.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation files('libs/CircleImageView-master/gradle/wrapper/gradle-wrapper.jar')
    implementation 'com.shitij.goyal:slide-button:1.0.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    implementation 'com.rengwuxian.materialedittext:library:2.1.4'
    implementation 'com.github.shts:StoriesProgressView:3.0.0'
    implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
    implementation 'com.tomer:fadingtextview:2.5'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.andkulikov:transitionseverywhere:1.8.1'

    implementation 'com.android.support:exifinterface:28.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'androidx.annotation:annotation:1.0.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.android.support:support-v13:28.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'com.android.support:mediarouter-v7:28.0.0'
    implementation 'androidx.mediarouter:mediarouter:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.android.support:palette-v7:28.0.0'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'com.android.support:leanback-v17:28.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.leanback:leanback:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha09'
    implementation 'androidx.navigation:navigation-fragment:2.0.0-rc02'
    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha09'
    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha09'
    implementation 'androidx.navigation:navigation-ui:2.0.0-rc02'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0-rc02'
    implementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha09'
    implementation 'androidx.navigation:navigation-ui-ktx:2.0.0-rc02'
    implementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
    implementation 'androidx.navigation:navigation-runtime:2.0.0-rc02'
    implementation 'androidx.test.espresso:espresso-contrib:3.1.1'
    implementation 'com.android.support.test:rules:1.0.2'
    implementation 'androidx.test:rules:1.1.1'
    implementation 'com.android.databinding:library:3.3.0'
    implementation 'androidx.databinding:databinding-runtime:3.3.0'
    implementation 'com.android.databinding:baseLibrary:3.3.0'
    implementation 'androidx.databinding:databinding-common:3.3.0'
    implementation 'com.android.databinding:compiler:3.1.4'
    implementation 'androidx.databinding:databinding-compiler:3.3.0'
    implementation 'com.android.databinding:adapters:3.3.0'
    implementation 'androidx.databinding:databinding-adapters:3.3.0'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.google.android.gms:play-services-ads:17.1.2'
    implementation 'com.google.android.gms:play-services-wearable:16.0.1'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    compileOnly 'com.google.android.wearable:wearable:2.4.0'
    implementation 'com.google.android.support:wearable:2.4.0'
    annotationProcessor 'com.android.databinding:compiler:3.1.4'
    annotationProcessor 'androidx.databinding:databinding-compiler:3.3.0'

}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

我在设计视图中收到以下错误消息:

无法实例化以下类: - de.hdodenhof.circleimageview.CircleImageView(打开类,显示异常,清除缓存)提示:在您的自定义中使用 View.isInEditMode() 在 IDE 中显示时跳过代码或显示示例数据的视图。如果这 是意外错误你也可以尝试构建项目,然后 手动刷新布局。异常详情 java.lang.IllegalArgumentException:不支持 ScaleType FIT_XY。 在 de.hdodenhof.circleimageview.CircleImageView.setScaleType(CircleImageView.java:134) 在 android.widget.ImageView.(ImageView.java:203) 上 android.widget.ImageView.(ImageView.java:172) 在 de.hdodenhof.circleimageview.CircleImageView.(CircleImageView.java:98) 在 de.hdodenhof.circleimageview.CircleImageView.(CircleImageView.java:94) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 在 android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863) 在 android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:837) 在 android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 在 android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866) 在 android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:837) 在 android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 在 android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866) 在 android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:837) 在 android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 在 android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866) 在 android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:837) 在 android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:515) android.view.LayoutInflater.inflate(LayoutInflater.java:394)

我在 build.gradle 应用模块文件中收到此错误消息:

使用 groupId com.android.support 和 androidx.* 的依赖项不能 合而为一 IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='support-v4', myVersion='26.1.0', myPacking='aar', myClassifier='null'} 和 IdeMavenCoordinates{myGroupId='androidx.documentfile', myArtifactId='documentfile', myVersion='1.0.0', myPacking='aar', myClassifier='null'} 不兼容的依赖少... (Ctrl+F1) 检查信息:有一些库或工具的组合和 不兼容或可能导致错误的库。一个这样的 不兼容正在编译一个版本的 Android 支持 不是最新版本的库(或者特别是版本 低于你的 targetSdkVersion)。问题 ID:GradleCompatible

【问题讨论】:

    标签: java android android-layout gradle build.gradle


    【解决方案1】:

    您同时拥有 AndroidX 库和 Support 库

    您需要迁移到 AndroidX

    转到重构 -> 迁移到AndroidX -> 迁移

    您的 build.gradle 文件:

    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
    
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "naik.dattaraj.meme2"
            minSdkVersion 22
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
            multiDexEnabled true
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/notice.txt'
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        //AndroidX libraries
        implementation 'androidx.appcompat:appcompat:1.0.2'
        implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
        implementation 'androidx.gridlayout:gridlayout:1.0.0'
        implementation 'androidx.mediarouter:mediarouter:1.0.0'
        implementation 'androidx.palette:palette:1.0.0'
        implementation 'androidx.leanback:leanback:1.0.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'androidx.exifinterface:exifinterface:1.0.0'
        implementation 'androidx.annotation:annotation:1.0.1'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        implementation 'androidx.legacy:legacy-support-v13:1.0.0'
        implementation 'androidx.test.espresso:espresso-core:3.1.1'
        testImplementation 'junit:junit:4.12'
        implementation 'com.google.android.material:material:1.0.0'
        //Navigation
        implementation 'androidx.navigation:navigation-fragment:2.0.0-rc02'
        implementation 'androidx.navigation:navigation-ui:2.0.0-rc02'
        implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0-rc02'
        implementation 'androidx.navigation:navigation-ui-ktx:2.0.0-rc02'
        implementation 'androidx.navigation:navigation-runtime:2.0.0-rc02'
        implementation 'androidx.test.espresso:espresso-contrib:3.1.1'
        implementation 'androidx.test:rules:1.1.1'
        //firebase
        implementation 'com.firebase:firebase-client-android:2.5.2'
        implementation 'com.google.firebase:firebase-database:18.0.0'
        implementation 'com.firebaseui:firebase-ui-database:2.1.0'
        implementation 'com.google.firebase:firebase-auth:18.1.0'
        implementation 'com.google.firebase:firebase-storage:18.1.0'
        //databinding
        implementation 'androidx.databinding:databinding-runtime:3.3.0'
        implementation 'androidx.databinding:databinding-common:3.3.0'
        implementation 'androidx.databinding:databinding-compiler:3.3.0'
        implementation 'com.android.databinding:adapters:3.3.0'
        implementation 'androidx.databinding:databinding-adapters:3.3.0'
        annotationProcessor 'androidx.databinding:databinding-compiler:3.3.0'
        //Google play services
        implementation 'com.google.android.gms:play-services:12.0.1'
        implementation 'com.google.android.gms:play-services-ads:17.1.2'
        implementation 'com.google.android.gms:play-services-wearable:16.0.1'
        implementation 'com.google.android.gms:play-services-maps:16.0.0'
        //Other libraries
        implementation 'com.shitij.goyal:slide-button:1.0.0'
        implementation 'com.github.bumptech.glide:glide:4.8.0'
        implementation 'com.squareup.picasso:picasso:2.5.2'
        implementation 'de.hdodenhof:circleimageview:3.0.0'
        implementation 'com.rengwuxian.materialedittext:library:2.1.4'
        implementation 'com.github.shts:StoriesProgressView:3.0.0'
        implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
        implementation 'com.tomer:fadingtextview:2.5'
        implementation 'com.andkulikov:transitionseverywhere:1.8.1'
        implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
        //compileOnly 'com.google.android.wearable:wearable:2.4.0'
        //implementation 'com.google.android.support:wearable:2.4.0'
    }
    apply plugin: 'com.google.gms.google-services'
    com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
    

    这应该工作.........

    【讨论】:

    • 我的 build.gradle 错误完全消失了。非常感谢。
    【解决方案2】:

    第二个错误:

    第二个错误是因为您尝试使用带有 AndroidX 依赖项的 android。混合依赖不是这样工作的。您必须将所有 android 依赖项转换为 AndroidX。这意味着您不能使用 Android 支持库。您需要将它们替换为等效的 AndroidX 库。

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    

    以上依赖项需要更改为 AndroidX 等效项。

    第一个错误:

    第一个错误是因为您直接使用CircleImageView 源并且它没有设置View.isInEditMode()。请尝试以下操作:

    替换这一行:

    implementation files('libs/CircleImageView-master/gradle/wrapper/gradle-wrapper.jar')
    

    用这一行:

    implementation 'de.hdodenhof:circleimageview:3.0.0'
    

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 2019-01-25
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      相关资源
      最近更新 更多