4

I am currently using IntelliJ IDEA 2018.3.4 which I am trying to integrate with Scala but to no avail.

I have installed the Scala and SBT plugins and used the following steps in creating my project:

  • File > Create New Project
  • Selected Java from the left
  • Selected Scala from the right > Next
  • Entered the name of the project > FINISH

From there, the project is created. Following other guides, I then:

  • Right click on the src directory
  • New > File
  • Enter main/scala/Main.scala
  • And enter the following code in there:

Code:

package main.scala

object Main {
  def main(args: Array[String]): Unit = {
    println("Hello World")
  }
}

But after right clicking in the editor and selecting Run Main, I get the following message:

Error: Could not find or load main class

Has anyone experienced this or can provide any solution?

Note

I have also tried creating a Scala application with sbt but the syncing process for the sbt dump never ends or gives an error and when I run the project, I get the same error.

Omari Celestine
  • 1,405
  • 1
  • 11
  • 21

2 Answers2

1

For Intellj IDEA, probably you will need to double check your module settings, and see if your scala folder is marked as sources root.

Check this URL for more details: https://www.jetbrains.com/help/idea/creating-and-managing-modules.html

Vinh Truong
  • 388
  • 1
  • 10
1

When I experienced this issue after recreating your situation almost exactly step-by-step, what fixed the problem was putting the scala file, in your case Main.scala, in another package, named anything you want it to be, inside main/scala. Ultimately, the scala file's path would be something like

main/scala/<package-name>/Main.scala

Then, after fixing the package name in the scala file and running the scala file through IntelliJ, everything worked as it was supposed to.

Chris Gong
  • 8,031
  • 4
  • 30
  • 51