问题描述
每个支持设计小部件都出现错误。像recyclerview,协调器布局等。每次,我添加一个支持设计小部件,它显示
I am having error on every support design widget. Like the recyclerview, coordinator layout etc. Everytime, I add a support design widget it is showing
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
在布局问题部分。我正在使用api 28.0.0-rc01,gradle 4.4 android 3.1.4。这是我的build.gradle(app)文件
on layout issue section. I'm using api 28.0.0-rc01, gradle 4.4 android 3.1.4. Here, is my build.gradle (app) file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.android.test5test"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.2'
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
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'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support:cardview-v7:28.0.0-rc01'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
}
这是我的布局文件
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/work_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="5dp"
app:tabTextColor="@color/white"
app:tabSelectedTextColor="@color/colorAccent"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
</LinearLayout>
这是错误的堆栈跟踪
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:180)
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:118)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:213)
at android.support.design.widget.TabLayout$SlidingTabIndicator.setSelectedIndicatorHeight(TabLayout.java:2402)
at android.support.design.widget.TabLayout.<init>(TabLayout.java:425)
at android.support.design.widget.TabLayout.<init>(TabLayout.java:399)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:222)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:209)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:337)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:348)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:248)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:544)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:678)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我已经检查了View类文件,但是其中有 OnUnhandledKeyEventListener。不知道为什么会发生此问题。请告诉我如何解决此问题。
I have checked the View class file, but the "OnUnhandledKeyEventListener" was in there. Don't know why this problem is occurring. Please, tell me how to solve this problem.
推荐答案
在应用程序> src中打开 styles.xml > main> res> values文件夹并更改此行
Open styles.xml in app > src > main > res > values folder and change this line
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
到
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
这篇关于找不到OnUnhandledKeyEventListener类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!