按照指南制作小型聊天应用。 但每当我运行应用程序并尝试打开聊天活动时,我都会收到此工具栏错误
错误类android.support.v7.widget.toolbar
已经尝试过来自另一个踏板的解决方案,但仍然会出现此错误。 我究竟做错了什么?谢谢!
logcat的
EXCEPTION: main
Process: com.leti.isaevruslan.diplomchat, PID: 31648
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.leti.isaevruslan.diplomchat/com.leti.isaevruslan.diplomchat.ui.activities.ChatActivity}:
android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class android.support.v7.widget.toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class android.support.v7.widget.toolbar
Caused by: android.view.InflateException: Binary XML file line #24: 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/com.leti.isaevruslan.diplomchat-2/base.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_dependencies_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_0_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_1_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_2_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_3_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_4_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_5_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_6_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_7_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_8_apk.apk",
zip file "/data/app/com.leti.isaevruslan.diplomchat-2/split_lib_slice_9_apk.apk"],
nativeLibraryDirectories=[/data/app/com.leti.isaevruslan.diplomchat-2/lib/x86, /system/lib, /vendor/lib]]
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.rInflate(LayoutInflater.java:861)
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:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.leti.isaevruslan.diplomchat.ui.activities.ChatActivity.onCreate(ChatActivity.java:37)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
05-04 21:53:22.034 31648-31648/com.leti.isaevruslan.diplomchat
E/AndroidRuntime:
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
依赖关系
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:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.firebase:firebase-auth:9.6.1'
Activity.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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.leti.isaevruslan.diplomchat.ui.activities.LoginActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame_layout_content_chat"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
<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="wrap_content"
android:minHeight="@dimen/abc_action_bar_default_height_material"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:2)
使用android.support.v7.widget.Toolbar
代替android.support.v7.widget.toolbar
。
试试这个:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/abc_action_bar_default_height_material"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name"/>
答案 1 :(得分:1)
它是工具栏:android.support.v7.widget.Toolbar
注意T是大写