Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.1 does not render xml file due to a java class missing

It always shows me this error in the massages:

java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener

My project is literally Hello, World! and I just open Android Studio and click on the empty activity and then wait for the build to finish, but it doesn't render the app.

I reinstalled Android Studio and JDK 10. But it doesn't work. The project shows fine in virtual device and I can even edit Hello, World! to any string, but in the XML view, it just shows a white screen:

Screenshot of project Hello, World!.

Here is the stack trace:

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)
like image 978
Parsa Mahmoodi Avatar asked Jul 09 '18 05:07

Parsa Mahmoodi


People also ask

Why doesn’t Android Studio start after installing Android Studio?

Android Studio doesn’t start after installing version 4.2 Studio tries to import previous.vmoptions and sanitize them to work with the garbage collector used by JDK 11. If that process fails, the IDE may not start for certain users who set custom VM options in the.vmoptions file.

How to fix unknown_JVMTI_error error in Android Studio?

JVMTI error: UNKNOWN_JVMTI_ERROR To work around this issue in Android Studio 3.5, click Run to re-deploy your app and see your changes. Note: This issue ( #135172147) is fixed in Android Studio 3.6 Canary 6 and higher.

How do I know which libraries are missing from Android Studio?

If not, you can use a terminal to navigate to the Android Studio installation directory and execute the bin/lldb/bin/LLDBFrontend --version command line to learn which libraries are missing. Typically, the missing library is ncurses5 as some recent Linux distributions have already upgraded to ncurses6.

Why am I getting recording failed to stop errors in Android Studio?

You may experience "Recording failed to stop" errors in the Android Studio CPU Profiler when you select the Sample Java Methods or Trace Java Methods configurations. These are often timeout errors, especially if you see the following error message in the idea.log file:


3 Answers

Yes, it happens. You can fix it easily.

The 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'

The second method:

Open file style.xml under resvaluesstyle.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">
like image 71
Robin Avatar answered Oct 11 '22 09:10

Robin


- 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 always use the stable version of every dependency.

The issue you faced was due to using an alpha version of the AppCompat library. Use the stable version to get rid of this issue now and in the future.

1. Use the android.support stable version

Currently 27.1.1 is the latest version of AppComactV7. You can see the Maven Repo link to find out the 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 the same version for all support versions. Also ignore the design library if you are not already using it.

2. Downgrade compileSdkVersion and targetSdkVersion (optional)

You also need to downgrade your compileSdkVersion and targetSdkVersion to remove some Gradle warnings.

So use the below versions.

compileSdkVersion 27
targetSdkVersion 27

Read about Alpha and Beta releases.

like image 3
Khemraj Sharma Avatar answered Oct 11 '22 08:10

Khemraj Sharma


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.

like image 2
Jacqueline Avatar answered Oct 11 '22 09:10

Jacqueline