Kotlin Foo::class.java “Unresolved Reference: Java” error

后端 未结 10 1219
予麋鹿
予麋鹿 2020-12-15 17:11

I am trying to convert my Java code of HomePage.class to Kotlin. I am following the instructions on Kotlin.org:

getClass()

10条回答
  •  -上瘾入骨i
    2020-12-15 17:26

    It turns out, I was using an older version of Kotlin, and it wasn't configured correctly. I edited the gradle file to include the latest beta version, and selected the option that configures Kotlin, and it works now.

    In gradle:

    buildscript {
        ext.kotlin_version = '1.0.0-beta-3594'
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        }
    }
    ...
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    }
    

提交回复
热议问题