无法在Scala Intellij中找到或加载主类(classname) [英] Could not find or load main class (classname) in Scala Intellij
问题描述
我正在学习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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!