eclipse 编辑器不包含主类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1113729/
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-09-10 18:50:16  来源:igfitidea点击:

Editor does not contain a main type

eclipsescala

提问by Helen Neely

Just going through the sample Scala code on Scala website, but encountered an annoying error when trying to run it.

刚刚浏览了 Scala 网站上的示例 Scala 代码,但在尝试运行它时遇到了一个恼人的错误。

Here's the code: http://www.scala-lang.org/node/45. On running it on Eclipse, I got this message 'Editor does not contain a main type' that prevents it from running.

这是代码:http: //www.scala-lang.org/node/45。在 Eclipse 上运行它时,我收到这条消息“编辑器不包含主类型”,阻止它运行。

Is there anything I need to do...i.e break that file into multiple files, or what?

有什么我需要做的...即将该文件分成多个文件,还是什么?

采纳答案by nuriaion

I have this problem a lot with Eclipse and Scala. It helps if you clean your workspace and rebuild your Project.

我在 Eclipse 和 Scala 中经常遇到这个问题。如果您清理工作区并重建项目,它会有所帮助。

Sometimes Eclipse doesn't recognize correctly which files it has to recompile :(

有时 Eclipse 不能正确识别哪些文件必须重新编译:(

Edit: The Code runs fine in Eclipse

编辑:代码在 Eclipse 中运行良好

回答by milkplus

In Eclipse, make sure you add your source folder in the project properties -> java build path -> source. Otherwise, the main() function may not be included in your project.

在 Eclipse 中,确保在项目属性 -> java 构建路径 -> 源中添加源文件夹。否则,您的项目中可能不包含 main() 函数。

回答by ultra99

You have to make sure that your .java files are in the.src folder in eclipse. I had the same exact problem until I got it figured out.

您必须确保您的 .java 文件位于 eclipse.src 文件夹中。在我弄清楚之前,我遇到了同样的问题。

回答by static

A simpler way is to close the project and reopen it.

更简单的方法是关闭项目并重新打开它。

回答by kholofelo Maloma

Just make sure that the folder you work in is added to the built path:

只需确保您工作的文件夹已添加到构建路径中:

right-clickyour folder --> build Path--> Use as source Folder

right-click你的文件夹 --> build Path-->Use as source Folder

and it should now find maintherein.

它现在应该在main其中找到。

回答by Anand Dhole

I had the same problem. I tried all sorts of things. And I came to know that

我有同样的问题。我尝试了各种方法。我开始知道

  1. My .java files were not linked and
  2. they were not placed in the 'src' folder.
  1. 我的 .java 文件没有链接并且
  2. 它们没有放在“src”文件夹中。

Things I did:

我做的事情:

Project properties >> Java Build Path >> Source

项目属性 >> Java 构建路径 >> 源代码

  • Deleted the original 'src' folder which was empty using 'Remove' option
  • Added the source that contained my source .java files using the 'Add Folder' option
  • 使用 'Remove' 选项删除了原来为空的 'src' 文件夹
  • 使用“添加文件夹”选项添加了包含我的源 .java 文件的源

This solved the error.

这解决了错误。

回答by Fei

You can try to run the main function from the outline side bar of eclipse.

可以尝试从eclipse的大纲侧边栏运行main函数。

solution

解决方案

回答by Mohit Singh

***

Just close and reopen

只需关闭并重新打开

*** your project in eclipse. Sometime there are linkage problems. This solved my problem

*** 你在 eclipse 中的项目。有时会出现链接问题。这解决了我的问题

回答by AbsintheSyringe

What you should do is, create a Java Project, but make sure you put this file in the package file of that project, otherwise you'll encounter same error.

你应该做的是,创建一个Java项目,但一定要把这个文件放在那个项目的包文件中,否则你会遇到同样的错误。

enter image description here

在此处输入图片说明

回答by rwc

A quick solution:

一个快速的解决方案:

First, exclude the package: Right click on the source package >> Build Path >> Exclude

首先排除包:在源包上右键>>构建路径>>排除

Then include it back: Right click on the source package >> Build Path >> Include

然后将其包含回来:右键单击源包>>构建路径>>包含