1

Update: It may have to do with the fact that I'm using the latest androidx.support libraries rather than old android.support. Will investigate in that direction and update again. update 2: Still get the same error even after creating a project that uses the old android.support.* libraries. Pasting the app build.gradle at the end of this.

I'm getting the following IDE error when opening the Anko Layout Preview tool window. The full code of my toy project is below the stack trace:

java.lang.IllegalArgumentException: java.lang.ClassCastException@5d0792b9
    at sun.reflect.GeneratedConstructorAccessor1138.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.kotlin.android.dslpreview.DslPreviewClassResolver$Companion.createTypeMapper(DslPreviewClassResolver.kt:131)
    at org.jetbrains.kotlin.android.dslpreview.DslPreviewClassResolver$Companion.access$createTypeMapper(DslPreviewClassResolver.kt:122)
    at org.jetbrains.kotlin.android.dslpreview.DslPreviewClassResolver.resolveClassDescription(DslPreviewClassResolver.kt:116)
    at org.jetbrains.kotlin.android.dslpreview.DslPreviewClassResolver.getOnCursorPreviewClassDescription(DslPreviewClassResolver.kt:59)
    at org.jetbrains.kotlin.android.dslpreview.AnkoNlPreviewManager.refresh(AnkoNlPreviewManager.kt:122)
    at org.jetbrains.kotlin.android.dslpreview.AnkoNlPreviewManager.getBoundXmlFile(AnkoNlPreviewManager.kt:81)
    at com.android.tools.idea.uibuilder.editor.NlPreviewForm.getFile(NlPreviewForm.java:220)
    at com.android.tools.idea.uibuilder.editor.NlPreviewForm.initNeleModelWhenSmart(NlPreviewForm.java:422)
    at com.android.tools.idea.uibuilder.editor.NlPreviewForm.lambda$initNeleModel$5(NlPreviewForm.java:418)
    at com.intellij.openapi.project.DumbServiceImpl.lambda$smartInvokeLater$7(DumbServiceImpl.java:438)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:447)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:431)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:415)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:817)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:758)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:394)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Following is the code of my sole .kt file:

package com.foobar.deleteme

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import org.jetbrains.anko.*

class MainActivityUI : AnkoComponent < MainActivity > {
    override fun createView(ui: AnkoContext<MainActivity>) = ui.apply {
        verticalLayout {
            button("bar")
        }
    }.view
}

class MainActivity : AppCompatActivity() {

    override fun onCreate(bundle: Bundle?) {
        super.onCreate(bundle)
        MainActivityUI().setContentView(this)
    }
}

I got the same error in my main project and therefore I created a small toy project with just one activity. I got the same error again.

app build.gradle: (ext.kotlin_version = '1.3.21' and ext.anko_version = '0.10.8')

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.softrithms.deleteme"
        minSdkVersion 26
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation "com.android.support.constraint:constraint-layout:1.1.0-beta4"
    implementation "org.jetbrains.anko:anko:$anko_version"
    implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
}
user2297550
  • 3,142
  • 3
  • 28
  • 39

0 Answers0