Could not find or load main class in scala in intellij IDE

Viewed 51656

I have searched for this error, but the answers were for Java, but my case is Scala. I am trying to run this project in IntelliJ IDE sentimenAnalysis, but it throws an error. This is also the structure of the project. Class Not found

Update 1 According to answers, Adding $ at the end of the name of search class enter image description here

Update 2 after adding sbt task: enter image description here

Update 3 My problem was resolved by importing the project, instead of getting it directly from GitHub, probably the manual configuration that Mike Allen said could resolve the problem, but I couldn't successfully apply that.

9 Answers

My problem was resolved when I marked src folder as sourced root. Click with the right button in src folder -> Mark Directory as -> Sources root

You will get this error if you tried to open the project and imported it incorrectly. I would open the project like this in Intellij:

File>New> Project from Existing Source>(select) Import project from external model>
(select)sbt

click Next>Finish

To fix this issue in my project I invalidated caches and restarted:

enter image description here

In my case the object in the object MyObject extends App was nested, if you have it unested meaning in your scala file it's not under any other object it made it work.

Netsted caused this error in intellij:

object External {
  object MyMain extends App // Could not find or load main class in scala in intellij IDE

}

While the below unested worked:

object External { }
object MyMain extends App // Worked!

Hi I solved this problem by defining the class in src package under main and by setting up the configuration as default.enter image description here

Had a similar problem with latest Intellij IDEA build (2022.1.1) and scala 3.1.2 - both sbt and Intellij scala projects. For me the solution was to use non-ascii path.

I met the same issue, please check the whole execute command and check the configuration, make sure the compiled files path is correctly configured. refer to my screenshot:
refer to my screenshot

Related