问题
Always shows me the error in the massages
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
My project is literally hello world and I just open android studios and click on the empty activity and then wait for the build to finish but it doesn't render the app. I reinstalled android studios and JDK10. but it doesn't work. the project shows fine in virtual device and i can even edit hello world to any string, but in XML view, it just shows a white screen
.here is the stack:
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.v7.widget.ActionBarContainer.<init>(ActionBarContainer.java:62)
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.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.android.layoutlib.bridge.bars.BridgeActionBar.<init>(BridgeActionBar.java:89)
at com.android.layoutlib.bridge.bars.AppCompatActionBar.<init>(AppCompatActionBar.java:68)
at com.android.layoutlib.bridge.impl.Layout.createActionBar(Layout.java:277)
at com.android.layoutlib.bridge.impl.Layout.<init>(Layout.java:161)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:288)
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)
回答1:
Yes, it happens. You can fix it easily.
First Method: Open build.gradle(Module: app) under Gradle Scripts and change version alpha3 to alpha1 and Sync now
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Second Method: Open style.xml under res -> values -> style.xml and change this line
style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
put Base. before Theme.AppCompat.Light.DarkActionBar like
style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Hope problem will be solved.
回答2:
- Use Alpha/Beta at your Own Risk
- You are developing an app, so you don't want to face these types of issues. So I suggest you use always stable version of every dependency.
The issue you faced was due to using alpha version of AppCompat library. Use stable version to get rid of this issue now and in future.
1. Use android.support
stable version
Currently 27.1.1 is latest version of AppComactV7. You can see Maven Repo link to find out latest.
final def SUPPORT_VERSION = "27.1.1"
implementation "com.android.support:appcompat-v7:$SUPPORT_VERSION"
implementation "com.android.support:design:$SUPPORT_VERSION" // use only if already using
I use definitions to have same version for all support versions. Also ignore design library if you are not already using it.
2. Downgrade compileSdkVersion
and targetSdkVersion
(Optional)
You also need to downgrade your compileSdkVersion
& targetSdkVersion
to remove some gradle warnings.
so use below versions
compileSdkVersion 27
targetSdkVersion 27
Read about Alpha & Beta releases.
回答3:
Go to
Gradle scripts>build.gradle(module app) > change 'com.android.support:appcompat-v7:28.0.0-alpha3' to 'com.android.support:appcompat-v7:28.0.0-alpha1'
You may have something other than alpha3 after "-v7:28.0.0-" whatever it is just change it to alpha1.
回答4:
You can fix it easily.
Open build.gradle(Module: app) under Gradle Scripts and update the version of appcompat to given below and Sync now
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
回答5:
Use:
implementation 'com.android.support:appcompat-v7:27.1.1'
and of course
compileSdkVersion 27
Until version 28 full ver comes!
来源:https://stackoverflow.com/questions/51238779/android-studio-3-1-does-not-render-xml-file-due-to-a-java-class-missing