首页 > 解决方案 > Kotlin - 应用程序项目模板 - 找不到错误主类

问题描述

我正在使用 IntelliJ IDEA 2021.1(社区版) - 构建 #IC-211.6693.111,构建于 2021 年 4 月 6 日。我创建了一个新的 kotlin 项目 - 项目模板(JVM):应用程序,构建系统:Gradle Kotlin,项目 JDK: 1.8 版本 1.8.0_281。在“scr/main/kotlin”文件夹中,我创建了一个带有简单代码的 kotlin 文件,例如“fun main(){println(“Hi!”)}。当我尝试运行该文件时(构建正常),我收到这个错误:“Could not find or load main class MyAppKt”。我做错了什么?

标签: kotlin

解决方案


Did you also add your main class to the build.gradle file?

mainClassName = "projectPackage.MyAppKt"

I assume if you are adding the MyAppKt file manually it is not added to the build.grale. But clearly more information about the project would help here. Meanwhile check this post Kotlin - Error: Could not find or load main class _DefaultPackage


推荐阅读