找不到或加载主类com.weekdays.claobj.Ann1

时间:2019-05-27 11:09:51

标签: scala intellij-idea

enter image description here我的代码未显示任何编译错误,但执行时失败,并出现以下错误:

C:\Program Files\Java\jdk-11.0.2\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.1\lib\idea_rt.jar=51590:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\ag186097\IdeaProjects\Prwatech\target\scala-2.11\classes;C:\Users\ag186097\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.11.8.jar com.weekdays.claobj.Ann1
**Error: Could not find or load main class com.weekdays.claobj.Ann1
Caused by: java.lang.ClassNotFoundException: com.weekdays.claobj.Ann1**

我尝试将主文件夹设置为仍然没有执行的根文件夹

package com.weekdays.claobj

class Annon1Obj {

  var age:Int = 29

  def show():Unit = {

    println("this is the age of raju " + age)}

}

object Ann1{

  def main(args: Array[String]): Unit = {

    var n = new Annon1Obj()

    n.show()

  }

}

1 个答案:

答案 0 :(得分:0)

  

https://www.scala-lang.org/download/

阅读第一步,确保已安装JDK 8。

如果已安装jdk 8,则可以选择jdk 8作为项目jdk。

文件->项目结构->在那里您会找到一个下拉列表,您可以在其中找到可以更改它的JDK。

将您的jdk版本降级到8,这样就可以正常工作。