153 votes

Impossible de charger AppCompat ActionBar avec une erreur inconnue dans android studio

Ci-dessous mon fichier xml. Dans l'aperçu il y a deux erreurs'Failed pour charger AppCompat ActionBar avec une erreur inconnue' & 'n'a pas instaniate plus d'une classe. Comment jamais, je suis capable d'exécuter l'application.Mais l'application se bloque et dans le Logcat pas d'erreurs sont affichés.

C'est ma capture d'écran aperçuenter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="506dp" />

    <LinearLayout
        android:id="@+id/layout_main"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1"
        tools:context=".Activity.MainActivity">


    <LinearLayout
        android:id="@+id/main_layout"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.7"
        tools:context=".Activity.MainActivity">

        <!-- our tablayout to display tabs  -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:tabMode="scrollable"
            app:tabSelectedTextColor="@color/colorBlack"
            app:tabTextColor="@color/colorWhite"
            android:background="@color/colorOran"
            android:minHeight="?attr/actionBarSize"
            />

        <!-- View pager to swipe views -->
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>

        <LinearLayout
            android:id="@+id/ll"
            android:layout_width="match_parent"
            android:layout_height="64dp"
            android:layout_alignParentBottom="true"
            android:background="#ffffff"
            android:orientation="horizontal"
            android:layout_weight="0.3"
            android:weightSum="4"
            tools:layout_editor_absoluteX="8dp"
            android:layout_marginBottom="8dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

            <ImageView
                android:id="@+id/btn_home"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/ta_home_icon"
                android:background="@color/colorOran"
                android:layout_marginRight="1dp"
                android:scaleType="fitCenter"/>

            <ImageView
                android:id="@+id/btn_new"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/ta_todaydeals_icon"
                android:background="@color/colorOran"
                android:layout_marginRight="1dp"
                android:scaleType="fitCenter"/>

            <ImageView
                android:id="@+id/btn_fav"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/ta_fav_icon"
                android:background="@color/colorOran"
                android:layout_marginRight="1dp"
                android:scaleType="fitCenter"/>

            <ImageView
                android:id="@+id/btn_auth"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:src="@drawable/ta_franchie_icon"
                android:background="@color/colorOran"
                android:scaleType="fitCenter"
                android:layout_marginRight="1dp"
                />

        </LinearLayout>

    </LinearLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />


</android.support.v4.widget.DrawerLayout>

Ci-dessous est appbar_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jeyashri.kitchen.jeyashriskitchen.Activity.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorOran"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <ImageView
                android:id="@+id/app_logo"
                android:layout_width="80dp"
                android:layout_height="match_parent"
                android:src="@drawable/img"/>

            <ImageView
                android:id="@+id/btn_social"
                android:layout_width="75dp"
                android:layout_height="35dp"
                android:layout_marginRight="1dp"
                android:src="@drawable/share_icon" />

    </android.support.v7.widget.Toolbar>

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

    <include layout="@layout/content_main" />


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

326voto

Debashis Choudhury Points 3272

La solution à ce problème dépend de la version de l'Androïde de soutien de la bibliothèque que vous utilisez:

Bibliothèque de prise en charge 26.0.0-beta2

Cette android support library version a un bug causé par le problème évoqué

Dans votre fichier de build Gradle utilisation:

compile 'com.android.support:appcompat-v7:26.0.0'

avec:

buildToolsVersion '26.0.0' 

et

classpath 'com.android.tools.build:gradle:3.0.0-alpha8'

tout devrait fonctionner correctement maintenant.


Version de bibliothèque 28 (beta)

Ces nouvelles versions semblent souffrir de semblables difficultés de nouveau.

Dans votre res/values/styles.xml modifier l' AppTheme style de

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

pour

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

(note ajoutée Base.)

Ou, alternativement, d'une décote de la bibliothèque jusqu'à ce que le problème est résolu:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

276voto

tanchap Points 2731

trouvé sur ce site, cela fonctionne sur moi. Modifiez /res/values/styles.xml à partir de:

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

à:

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

26voto

Abhishek Points 273

Juin 2018 Problème résolu en utilisant une version différente de appcompact. Utilisez ces codes sur les dépendances de votre projet ...

Dans build.gradle (Module: app), ajoutez cette dépendance

 implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
 

Bonne codage ... :)

17voto

shellhub Points 516

Méthode 1:

Localiser /res/values/styles.xml

Changement

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

À

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

Méthode 2:

Modifier le fichier de modèle (localiser: android-studio/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/values/styles.xml.ftl )

Changement

 backwardsCompatibility!true>Theme.AppCompat<#else><#if
 

À

 backwardsCompatibility!true>Base.Theme.AppCompat<#else><#if
 

Regarder la solution sur YouTube

Solution

17voto

Muhammad Azam Points 153

J'ai également eu ce problème et il est résolu en tant que ligne de changement de res / values / styles.xml

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

à

  1. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  2. <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

les deux solutions ont fonctionné

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X