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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:04:40  来源:igfitidea点击:

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

javaeclipsescalaapache-sparkscala-ide

提问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 编译器配置:

scala compiler configuration

Scala编译器配置

Here is my run configuration:

这是我的运行配置:

run configuration

运行配置

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

这是我在控制台中显示的代码、文件结构和错误:

enter image description here

在此处输入图片说明

Here is the information Problem console:

这是信息问题控制台:

enter image description here

在此处输入图片说明

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,请使用以下过程:

  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.

  1. 转到窗口右上角的下拉菜单,然后选择“编辑配置”。

  2. 在弹出的屏幕上,选择左侧的“Scala-console”,在右侧的“使​​用模块的类路径和SDK”下选择您的模块名称。

enter image description here

在此处输入图片说明

回答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 classin IJIdea IU-182.4892.20 / Scala 2.13for .scalafile with such structure:

我有一个类似的问题。我有Could not find or load main classIJIdea 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, objectsto the separate .scalafile 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:

我遇到了相同的错误消息,以下解决方案对我有用:

  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").
  1. 右键单击项目。
  2. 单击 Scala。
  3. 选择选项“设置 scala 安装”。
  4. 选择 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:

我是如何解决这个问题的:

  1. Run my project via SBT like this: sbt my-project/run
  2. Stopped it (Ctrl+C)
  3. Run debug -- it works again.
  1. 像这样通过 SBT 运行我的项目:sbt my-project/run
  2. 停止它 (Ctrl+C)
  3. 运行调试——它再次运行。