java - XML 中的 "Failed to instantiate one or more class"错误,Android Studio

标签 java android xml

XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bgLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <Button
                android:id="@+id/button_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/button1"
                android:padding="16dp"
                android:layout_margin="8dp"/>

            <Button
                android:id="@+id/button_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:layout_margin="8dp"
                android:text="@string/button2"/>

            <Button
                android:id="@+id/button_3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:layout_margin="8dp"
                android:text="@string/button3"/>
        </LinearLayout>
    </ScrollView>

</android.support.design.widget.CoordinatorLayout>

这是 Gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.android.bottomsheettest"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
    lintOptions {
        disable 'RestrictedApi'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:26.0.1'
    compile "com.android.support:support-core-utils:26.0.1"
}

在 XML 预览中,有一个错误提示: Error

这很奇怪,因为它是一个 NullPointerException 错误。 我没有更新主 Activity 文件中的任何内容。

我计划为此添加一个底页,这就是我添加 Coordinate Layout 标签的原因。自从我添加了那个标签,我就找不到任何方法来消除这个错误。

最佳答案

在我删除了 lintOptions 和 allProject 组件并替换了依赖项后,错误得到了解决

compile 'com.android.support:design:26.0.1'

与:

compile 'com.android.support:design:26.0.0-alpha1'

关于java - XML 中的 "Failed to instantiate one or more class"错误,Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45650466/

相关文章:

java - 使用 objectify 如何获取对象的属性子集

java - 如何将字符串格式化为一行,StringUtils?

c# - 如何用根反序列化Xml而不是相同类型的多个子元素

android - 文本大小(dp)

java - 如何保持这个合并数组方法在边界内?

java - 如何在 Android 中部署 Moquette 代理?

java - 在 Android 5.0+ 中短时间间隔使用重复警报的正确方法是什么?

java - 使用 Google App Engine 的自定义 android 身份 validator

java - Hashmap返回空值问题

android - setKeyguardDisabledFeatures(componentName, DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE);无法在 android-q/Android 10 中运行