Android Studio运行Kotlin代码报错

- 问题

按照《第一行代码Android第三版》2.2节中新建了LearnKotlin.kt,输入了main函数,运行却报错如下

FAILURE: Build failed with an exception.

  • Where:
    Initialization script ‘C:\Users\stserver86001\AppData\Local\Temp\LearnKotlinKt_main__.gradle’ line: 27

  • What went wrong:
    A problem occurred configuring project ‘:app’.

Could not create task ‘:app:LearnKotlinKt.main()’.
SourceSet with name ‘main’ not found.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

解决办法

在.idea\gradle.xml中添加如下代码,重新按Ctrl+Shift+F10即可成功运行Kotlin代码
Android Studio运行Kotlin代码报错_第1张图片

你可能感兴趣的:(第一行代码android第三版)