Java Scala 错误:无法在 Scala IDE 和 Eclipse 中找到或加载主类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45540135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scala Error: Could not find or load main class in both Scala IDE and Eclipse
提问by Sun Ke
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.
这是我的问题,我知道类似问题有很多答案,但是在我尝试后没有一个有效。我同时使用 Scala IDE 4.6 和 eclipse Oxygen 来运行代码,但都因此错误而失败。
Here's my scala compiler configuration:
这是我的 Scala 编译器配置:
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.
从在线回答中,我已经尝试在构建之前清理项目,我还尝试了所有版本的 JVM 和 Scala 编译器,所有这些都没有帮助。
The code was directly import from a online course code, so I believe there shouldn't be any errors in the code.
代码是直接从在线课程代码中导入的,所以我认为代码中不应该有任何错误。
采纳答案by ktheitroadalo
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.
在您的情况下,在 src 内创建一个文件夹 main/scala 并复制其中的包。
Please follow herefor the project structure
请按照此处查看项目结构
I hope this helped!
我希望这有帮助!
回答by KayV
For Intellij IDE, use the following procedure:
对于 Intellij IDE,请使用以下过程:
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.
转到窗口右上角的下拉菜单,然后选择“编辑配置”。
在弹出的屏幕上,选择左侧的“Scala-console”,在右侧的“使用模块的类路径和SDK”下选择您的模块名称。
回答by Ramesh Hawking
In the eclipse -->project properties-->scala compiler ---> change the scala installation.
在eclipse中-->项目属性-->scala编译器--->更改scala安装。
It is working for me .
它对我有用。
回答by barbara
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.
据我所知,您的包结构是 com.ks.sparkscala,它与 FriendsByAge.scala、com.sundogsoftware.spark 中声明的不同,希望这会有所帮助。
回答by Dedkov Vadim
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:
我有一个类似的问题。我有Could not find or load main class
在IJIdea IU-182.4892.20 / Scala 2.13
为.scala
这样的结构文件:
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.
但是当我移到同一个包中//other traits, classes, objects
的单独.scala
文件时,我的问题就解决了。
回答by Saurabh Rana
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").
- 右键单击项目。
- 单击 Scala。
- 选择选项“设置 scala 安装”。
- 选择 Scala 安装(我选择了“固定 Scala 安装:2.10.6(捆绑)”)。
After this, it ran fine and did not give that error message.
在此之后,它运行良好并且没有给出该错误消息。
回答by Dedkov Vadim
Another one solution. I had a similar problem on project with Scala + SBT.
另一种解决方案。我在 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.
- 像这样通过 SBT 运行我的项目:sbt my-project/run
- 停止它 (Ctrl+C)
- 运行调试——它再次运行。