问题
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:
Go to the drop down at right top of window and select "Edit Configuration".
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:
- Right-click on the project.
- Click on Scala.
- Choose the option "Set the scala installation".
- 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:
- Run my project via SBT like this: sbt my-project/run
- Stopped it (Ctrl+C)
- 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