Scala Error: Could not find or load main class in both Scala IDE and Eclipse

岁酱吖の 提交于 2019-11-27 19:22:56

问题


Here is my problem, I know there are lots of answers for similar questions, however none of them worked after I tried. I'm using both Scala IDE 4.6 and eclipse Oxygen to run the code and all failed on this error.

Here's my scala compiler configuration:

Here is my run configuration:

Here is my code, file structure and error showed in console:

Here is the information Problem console:

From online answer, I have already tried to clean the project before building, I also tried all the versions of JVM and Scala compiler, all of those didn't help.

The code was directly import from a online course code, so I believe there shouldn't be any errors in the code.


回答1:


I think this should be your folder structure

Scala0
└── src
    └── main
        └── scala
            └── com.ks.sparkscala
                └── FriendsByAge

In your case create a folder main/scala inside src and copy the package inside it.

Please follow here for the project structure

I hope this helped!




回答2:


For Intellij IDE, use the following procedure:

  1. Go to the drop down at right top of window and select "Edit Configuration".

  2. On the pop-up screen, select "Scala-console" in left side, and in the right side, select your module name under "Use class path and SDK of module.




回答3:


In the eclipse -->project properties-->scala compiler ---> change the scala installation.

It is working for me .




回答4:


As far I can see your package structure is com.ks.sparkscala which is different from the declared one in FriendsByAge.scala, com.sundogsoftware.spark Hope this helps.




回答5:


I had a similar problem. I’ve got Could not find or load main class in IJIdea IU-182.4892.20 / Scala 2.13 for .scala file with such structure:

package ...

import ...

object Main extends App {
...
}

//other traits, classes, objects

But when I moved //other traits, classes, objects to the separate .scala file in the same package my problem was solved.




回答6:


I was experiencing the same error message and the below solution worked for me:

  1. Right-click on the project.
  2. Click on Scala.
  3. Choose the option "Set the scala installation".
  4. Select the Scala Installation (I selected "Fixed Scala Installation: 2.10.6(bundled").

After this, it ran fine and did not give that error message.




回答7:


Another one solution. I had a similar problem on project with Scala + SBT.

How I solved this one:

  1. Run my project via SBT like this: sbt my-project/run
  2. Stopped it (Ctrl+C)
  3. Run debug -- it works again.


来源:https://stackoverflow.com/questions/45540135/scala-error-could-not-find-or-load-main-class-in-both-scala-ide-and-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!