简体   繁体   English

Kotlin运行/调试配置

[英]Kotlin Run/Debug configuration

Have created simple Kotlin project in IDEA, with only Main.kt file 仅使用Main.kt文件在IDEA中创建了简单的Kotlin项目

在此处输入图片说明

When I have pressed K in margin to left of 'main', Run/Debug congiguration automatically was created 当我在'main'的左边按K时,自动创建了Run / Debug配置

在此处输入图片说明

But when I run this configuration, I got error: 但是,当我运行此配置时,出现错误:

在此处输入图片说明

Invalidate IDEA cache and restart does not help. 使IDEA缓存无效并重新启动没有帮助。

Please suggest how can I run Main.kt ? 请提出如何运行Main.kt建议?

This answer relates to an earlier version of the question, which was about confusion between scripting and compiled Kotlin. 该答案与该问题的早期版本有关,该问题与脚本编写和编译的Kotlin之间的混淆有关。

The problem 问题

You are trying to run a Kotlin file designed for compiled mode in scripting mode. 您正在尝试在脚本模式下运行为编译模式设计的Kotlin文件。

General Info 基本信息

Script mode 脚本模式

Scripts look like this: 脚本如下所示:

val a = 8
println(a)

They also usually have the extension .kts , which is why you had issues with the file picker. 它们通常也具有扩展名.kts ,这就是为什么文件选择器出现问题的原因。

Compiled mode 编译模式

Whereas what you wrote looks like this: 而您写的内容如下所示:

fun main(args: Array<String>) {
    val a = 8
    println(8)
}

These files normally have the extension .kt 这些文件通常具有扩展名.kt

Solution

You need to decide which mode you want to use, and use the appropriate file name and format for the file. 您需要确定要使用的模式,并为文件使用适当的文件名和格式。

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

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