5

Premise: I have already tried all solutions proposed in Stackoverflow similar questions where is suggested to rebuild, clean cache, or add to the style parent Base. with no result. So the error should have a different cause also because happens on project with the latest API level 28.

The editor doesn't work reporting that the following classes could not be instantiated:

  • android.support.design.widget.CoordinatorLayout
  • android.support.design.widget.AppBarLayout

Error 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.design.widget.AppBarLayout.<init>(AppBarLayout.java:190)
    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: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)

enter image description here

Gradle File:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "com.example.lore.myapplication"
        minSdkVersion 15
        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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
}
AndreaF
  • 11,975
  • 27
  • 102
  • 168
  • 2
    I've had this happen a lot recently. Sometimes an "Invalidate Caches/Restart" works, sometimes nothing does and it just randomly starts working again a few days later. I've mostly just given up on the design view for now. – TheWanderer Sep 23 '18 at 15:24
  • @TheWanderer nope I have tried many times and also totally cleared the whole Android Studio folders trying a clean setup – AndreaF Sep 23 '18 at 15:27
  • 1
    Like I said, sometimes it just doesn't work. I'm pretty sure it's an Android Studio bug. Have you tried the 3.2 RC or 3.3 Canary? Or even IntelliJ? – TheWanderer Sep 23 '18 at 15:29
  • @TheWanderer I'm using the latest version already officially released. I haven't tried if the preview versions have the same issue. – AndreaF Sep 23 '18 at 15:33
  • `28.0.0-rc` and `alpha` version of `28` dependency had the same problem and it sounds like the preview issue still persist in the stable version of 28. As you know, using 27.1.1 was the workaround or my answer [in here](https://stackoverflow.com/a/52020244/4409113) but however, using the latest version of Android studio like Canary version should solve it. – ʍѳђઽ૯ท Sep 23 '18 at 16:57
  • @ʍѳђઽ૯ท Check the gradle script piece posted above. I have used the latest release version. NOT rc or alpha. – AndreaF Sep 23 '18 at 19:08
  • Yes I have checked that: `it sounds like the preview issue still persist **in the stable version of 28**` But it worked on my side just now somehow. Pretty weird. – ʍѳђઽ૯ท Sep 23 '18 at 19:11

1 Answers1

1

Today has been officially released the latest (and till now Release Candidate)

Android Studio 3.2
Build #AI-181.5540.7.32.5014246, built on September 17, 2018

and build tools 2.0.3

In these versions the bug of Layout Editor not working with API 28 has been fixed. Install the updated IDE and tools, edit the gradle script accordingly end resync the project.

Silverstorm
  • 15,398
  • 2
  • 38
  • 52