错误是由以下命令触发的:
setContentView(R.layout.activity_item_list);
这段代码是使用“主/从流”创建新的Android项目时由Android Studio生成的。
虽然布局已经绘制出来了,但仍然出现错误。
I/zygote: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
at void com.junkradar.junkradar.ItemListActivity.onCreate(android.os.Bundle) (ItemListActivity.java:52)
at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7009)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7000)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1214)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2731)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2856)
at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1589)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
at void android.os.Looper.loop() (Looper.java:164)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6494)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/base.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_dependencies_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_resources_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_0_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_1_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_2_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_3_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_4_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_5_apk.apk", zip file "/data/app/com.jun
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
at android.view.ViewGroup .....
activity_item_list.xml:
<?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"
android:fitsSystemWindows="true"
tools:context=".ItemListActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
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"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/item_list" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
正如所提到的,此代码是由 Android Studio 3.2.1 自动生成的,并选择“主/详细流”类型的活动。