简体   繁体   English

错误:无法在 IntelliJ 中找到或加载主类 MainKt

[英]Error: Could not find or load main class MainKt in IntelliJ

I'm using IntelliJ.我正在使用 IntelliJ。
I can run Java or Kotlin project without any issue but I can't build Kotlin-JS project我可以毫无问题地运行 Java 或 Kotlin 项目,但我无法构建 Kotlin-JS 项目
I have the error Error: Could not find or load main class MainKt我有错误错误:无法找到或加载主类 MainKt

My IntelliJ information我的 IntelliJ 信息

IntelliJ IDEA 2018.2.6 (Community Edition) IntelliJ IDEA 2018.2.6(社区版)
Build #IC-182.5107.16, built on November 6, 2018构建 #IC-182.5107.16,构建于 2018 年 11 月 6 日
JRE: 1.8.0_152-release-1248-b22 amd64 JRE:1.8.0_152-release-1248-b22 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains sro JVM:JetBrains sro 的 OpenJDK 64 位服务器 VM
Linux 4.19.0-041900-generic Linux 4.19.0-041900-通用

File tree File tree文件树文件树

My main file contain just :我的主文件只包含:

    fun main(args: Array<String>) {
    val message = "Hello JavaScript!"
    println(message)
}

Run Menu运行菜单
Run menu运行菜单

I tried the option $KOTLIN_BUILDED$, $MODULE_WORKIN_DIR$, and to put the path manually but it didn't change anything.我尝试了 $KOTLIN_BUILDED$、$MODULE_WORKIN_DIR$ 选项并手动放置路径,但没有任何改变。

When I'm hovering MainKt with my mouse, a tooltip appear "Class 'MainKt' is in the default package" so IntelliJ see the class.当我用鼠标悬停 MainKt 时,会出现一个工具提示“Class 'MainKt' is in the default package”,以便 IntelliJ 看到该类。

My project settings seem to be ok我的项目设置似乎没问题

Project Structure part 1项目结构第 1 部分

Project Structure part 2项目结构第 2 部分

Project Structure part 3项目结构第 3 部分

I also tried to我也试过

Delete the *.iml file删除 *.iml 文件
Reinstalle IntelliJ重新安装 IntelliJ
Re add the main重新添加主
Invalidate cache and restarted使缓存无效并重新启动

Thanks you in advance提前谢谢你

The "Kotlin" run configuration runs Kotlin/JVM. “Kotlin”运行配置运行 Kotlin/JVM。 To run a Kotlin/JS program as a command-line program, you need to make sure you have node.js installed.要将 Kotlin/JS 程序作为命令行程序运行,您需要确保已安装 node.js。 Then you can either use IntelliJ IDEA Ultimate with the node.js plugin installed (in which case you will see a "run" icon in the gutter that will produce the correct run configuration automatically), or use Gradle to build and run your program from the command line.然后,您可以使用安装了 node.js 插件的 IntelliJ IDEA Ultimate(在这种情况下,您将在 gutter 中看到一个“运行”图标,它将自动生成正确的运行配置),或者使用 Gradle 构建和运行您的程序命令行。

Your main file need to be .kt你的主文件需要是.kt

You need to create it like this: src ->New ->Cotlin File/Class->File .您需要像这样创建它: src ->New ->Cotlin File/Class->File

NOT like this: src ->New ->File .不是这样的: src ->New ->File

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

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