繁体   English   中英

如何使用Java Intent解决此问题?

[英]How can I solve this problem with the Java Intent?

我将一些代码从Java转换为Kotlin。

fun backhome(home: View) {
    val intent_home = Intent(this, MainActivity)
    startActivity(intent_home)

fun backhome(home: View) {
    val intent_home = Intent(this, MainActivity::class.java)



    startActivity(intent_home)
}

首先,我尝试了第一个代码,这是Intent上的错误:以下任何函数都不能使用提供的参数来调用(Context!,Class <*>!)(String!,Uri!)

在第二个版本中,class.java有一个错误,作为未解决的引用

build.gradle

看来您的项目中缺少Kotlin插件。

在您的Build.Gradle(应用程序级别)文件中,添加这些。

在此处输入图片说明

另外,在同一文件中,将其添加到dependencies { }

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Build.Gradle(项目级别)文件中,确保已用BuildScript闭包形式编写了这些BuildScript

buildscript {
  ext.kotlin_version = '1.3.50'
  repositories {
     google()
     jcenter()
  }

 dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}

同步后,清理/重建项目。 希望错误会消失。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM