java - Kotlin 的 Intent

标签 java android android-intent kotlin

为什么我不能只写 class.kotlin 而不是写 class.java。 因为 AndroidMeActivity 是一个 kotlin 类,所以当我写这个时出现错误 ("Unsoloved refrence: java")

我该如何解决。

 val intent = Intent(this, AndroidMeActivity::class.java)

最佳答案

"Unsoloved refrence: java"

阅读Reflection

Reflection is a set of language and library features that allows for introspecting the structure of your own program at runtime.

确保,您添加了 org.jetbrains.kotlin:kotlin-gradle-plugin

buildscript {
    ext.kotlin_version = '1.2.30'
    ext.gradle_version = '3.0.1'

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$gradle_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

并检查您在下面添加的模块级别 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

关于java - Kotlin 的 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49356990/

相关文章:

android - 致命异常 : ThumbnailManager-1 while sharing images to Intent

java - Activity 错误甚至认为它在 list 中声明

java - 我的 JBoss 使用什么版本的 HornetQ?

java - 如何使用 Atmosphere 设计推送通知

java - Android - 在同一类中传递 uri/string/int

android - Google play 测试购买不再起作用

android - 在 Android 上,使用预填充的联系表打开添加新联系人的正确方法是什么?

java - 如何为JAXB设置浮点格式(使用eclipse moxy的json)

java - 如何在android上运行unity时共享内存?

android - 按下时更改操作栏按钮的背景颜色