膨胀类android.support.v7.widget_Toolbar时出错

时间:2018-08-09 12:53:45

标签: java android-studio gradle

我很难找出导致我的代码崩溃的原因。到目前为止,我已经搜索了两天,阅读了所有相关文章,并尝试了almos似乎合适的所有提议解决方案,以至于我不得不问自己:

我的应用在启动时崩溃,“运行”选项卡输出以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: es.tretornesp.clickerchat, PID: 20701
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{es.tretornesp.clickerchat/es.tretornesp.clickerchat.GroupList}: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.v7.widget_Toolbar
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6121)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
                   Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.v7.widget_Toolbar
                   Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.widget_Toolbar
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget_Toolbar" on path: DexPathList[[zip file "/data/app/es.tretornesp.clickerchat-2/base.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_dependencies_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_0_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_1_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_2_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_3_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_4_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_5_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_6_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_7_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_8_apk.apk", zip file "/data/app/es.tretornesp.clickerchat-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/es.tretornesp.clickerchat-2/lib/arm, /system/lib, /vendor/lib]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:609)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                      at es.tretornesp.clickerchat.GroupList.onCreate(GroupList.java:29)
                      at android.app.Activity.performCreate(Activity.java:6723)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6121)
E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

我正在使用Android Studio 3.1.4

以下是所有相关文件:

package es.tretornesp.clickerchat;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.miguelcatalan.materialsearchview.MaterialSearchView;

import java.util.ArrayList;

public class GroupList extends AppCompatActivity {

    private MaterialSearchView searchView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.group_list);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("Lista de grupos");
        toolbar.setTitleTextColor(Color.parseColor("#FFFFFF"));

        searchView = (MaterialSearchView) findViewById(R.id.search_view);    
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.group_menu_item, menu);
        MenuItem item = menu.findItem(R.id.action_search);
        searchView.setMenuItem(item);
        return true;
    }
}

这是group_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/group_list"
    android:theme="@style/AppTheme.NoActionBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="es.tretornesp.clickerchat.GroupList">

    <android.support.v7.widget_Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        />

    <com.miguelcatalan.materialsearchview.MaterialSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />


    <ListView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/toolbar"
        android:divider="#806326"
        android:id="@+id/listView"
        android:dividerHeight="1dp"/>

</RelativeLayout>

这是group_menu_item.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/image_search_action"
        android:orderInCategory="100"
        android:title="Buscar..."
        app:showAsAction="always"
        />

</menu>

这里是styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

</resources>

希望有人可以阐明这里可能发生的情况。

编辑:这是gradle文件,这些文件我照原样发布了。

build.gradle (Module: app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "es.tretornesp.clickerchat"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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'

    //Add library
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.firebaseui:firebase-ui:4.1.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'

    //Add search bar
    implementation 'com.miguelcatalan:materialsearchview:1.4.0'
}

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

build.gradle(项目:ClickerChat2)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="es.tretornesp.clickerchat">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".Chat"></activity>
        <activity android:name=".GroupList" android:exported="true"></activity>
    </application>

</manifest>

0 个答案:

没有答案