简体   繁体   English

无法加载AppCompat ActionBar

[英]Failed to load AppCompat ActionBar

I'm having problems rendering some code in android studio, I'm able to run the app but in the preview i got these errors: 我在android studio中渲染某些代码时遇到问题,我能够运行该应用程序,但在预览中却遇到了以下错误:

Failed to load AppCompat ActionBar with unknown error. 无法加载具有未知错误的AppCompat ActionBar。

The following classes could not be instantiated:
- android.support.v7.widget.AppCompatImageView (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.AppCompatTextView (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache)
- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.ActionBarOverlayLayout (Open Class, Show Exception, Clear Cache)

Here's my layout: 这是我的布局:

 <RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     android:paddingBottom="@dimen/activity_vertical_margin"
     tools:context=".MainActivity">

     <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
         android:layout_height="wrap_content" />

 </RelativeLayout>

And here's my graddle: 这是我的困境:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.sourcey.materialloginexample"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:design:25.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'
}

Any idea what compatibility problem do i have? 知道我有什么兼容性问题吗?

This one here solved my problem without changing library versions. 这里的这一解决了我的问题,而无需更改库版本。

Go to @styles xml file and change this line 转到@styles xml文件并更改此行

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> </style>

to: 至:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> </style>

You should change compileSdkVersion and targetSdkVersion . 您应该更改compileSdkVersiontargetSdkVersion Your problem has already answer, for more details you can check here https://stackoverflow.com/a/47067754/3797722 您的问题已得到解决,有关更多详细信息,您可以在这里检查https://stackoverflow.com/a/47067754/3797722

There are many ways to solve this problem. 有很多方法可以解决此问题。 The best and the easiest one is to open build.gradle (Module: app) file in Gradle Scripts folder. 最好和最简单的方法是在Gradle Scripts文件夹中打开build.gradle(模块:app)文件。 In dependencies you have to make only one change. 在依赖项中,您只需进行一项更改。 In second line of the dependencies curly bracket, change "alpha3" to "alpha1". 在依赖关系大括号的第二行中,将“ alpha3”更改为“ alpha1”。

It should work perfectly fine. 它应该工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM