Intellij IDEA 测试scala程序的时候: "Test is already defined as object Test"

使用Intellij IDEA 编写第一个SCALA程序的时候,会出现报错:

object TestScala {
  def main(args: Array[String]): Unit = {
    println("Hello,Scala")
  }

}
报错:Error:(9, 8) TestScalaObject is already defined as object TestScalaObject
object TestScalaObject {

原因:多重目录被设置为Source,导致出现多重对象

Intellij IDEA 测试scala程序的时候: "Test is already defined as object Test" 这里SCALA和MAIN目录都为蓝色,说明都为SOURCE,导致了对象重复。

解决方案:将MAIN的SOURCE去掉,即可

具体方法:1.选择main目录然后右键-》make Directory as -》unmark as root directory即可

Intellij IDEA 测试scala程序的时候: "Test is already defined as object Test"

2.选中项目右键--》opern module settings -》Modules-》Source--》去掉src/main目录即可

Intellij IDEA 测试scala程序的时候: "Test is already defined as object Test"