无法在Scala Intellij中找到或加载主类(classname)

编程入门 行业动态 更新时间:2024-10-25 20:18:56
本文介绍了无法在Scala Intellij中找到或加载主类(classname)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在学习Scala并在编写一些程序时。我正在关注

>错误:无法找到或加载主类动物

即使我删除了类,我也收到此错误或重命名该课程。 我在 src-> main-> scala->动物(包) - >动物(类)。

我试图在Google和这个网站上搜索解决方案,但这对我没有帮助。请让我知道我错过了什么。我在 Intellij 上运行此程序。

我也为其他程序收到此错误。

package Animal class Animal { def a:Int = 10 println(a)}

解决方案

也许您以前编写了一个 main 方法所在的应用程序 Animal 对象。删除指向此类的运行配置,或者通过使对象使用<$来使 Animal 应用程序c $ c> main 方法,例如:

package Animal 对象动物{ def a:Int = 10 def main(args:Array [String]):单位= println(a) }

您还可以使用 App trait并跳过 main 方法的定义,而不是按如下方式编辑代码。

package Animal object Animal extends App { def a:Int = 10 println(a) }

I am learning Scala and while writing some programs. I am getting following

> error:could not find or load main class Animal

I am getting this error even if I delete the class or rename the class. I am creating this program inside src->main->scala->Animal(package)->Animal(class).

I tried to search for solutions on Google and on this site but that did not help me. Please let me know what I am missing. I am running this program on Intellij.

I am getting this error for other programs as well.

package Animal class Animal { def a:Int = 10 println(a) }

解决方案

Perhaps you have previously written an application whose main method was in the Animal object. Either delete the run configuration that points to this class or make Animal an application by making it an object with a main method, e.g.:

package Animal object Animal { def a: Int = 10 def main(args: Array[String]): Unit = println(a) }

You can also use the App trait and skip the definition of the main method, than you could edit your code as follows.

package Animal object Animal extends App { def a: Int = 10 println(a) }

更多推荐

无法在Scala Intellij中找到或加载主类(classname)

本文发布于:2023-11-25 05:51:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   中找到   Scala   Intellij   classname

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!