편집기에 기본 유형이 없습니다.
Scala 웹 사이트의 샘플 Scala 코드를 살펴 보았지만 실행하려고 할 때 성가신 오류가 발생했습니다.
코드는 http://www.scala-lang.org/node/45 입니다. Eclipse에서 실행할 때 'Editor does not contain a main type'이라는 메시지가 표시되어 실행되지 않습니다.
내가해야 할 일이 있습니까? 즉, 해당 파일을 여러 파일로 나누거나 어떻게합니까?
Eclipse와 Scala에서이 문제가 많이 발생합니다. 작업 공간을 정리하고 프로젝트를 다시 빌드하면 도움이됩니다.
때때로 Eclipse는 재 컴파일해야하는 파일을 올바르게 인식하지 못합니다.
편집 : 코드는 Eclipse에서 잘 실행됩니다.
Eclipse에서 프로젝트 속성-> 자바 빌드 경로-> 소스에 소스 폴더를 추가해야합니다. 그렇지 않으면 main () 함수가 프로젝트에 포함되지 않을 수 있습니다.
.java 파일 이 eclipse 의 .src 폴더에 있는지 확인해야합니다 . 나는 그것을 알아낼 때까지 똑같은 문제가 있었다.
더 간단한 방법은 프로젝트를 닫고 다시 여는 것입니다.
작업중인 폴더가 빌드 된 경로에 추가되었는지 확인하십시오.
right-click
폴더-> build Path
->Use as source Folder
이제 main
거기에서 찾을 수 있습니다.
나는 같은 문제가 있었다. 나는 온갖 것을 시도했다. 그리고 나는 그것을 알게되었습니다
- 내 .java 파일이 연결되지 않았고
- 'src'폴더에 위치하지 않았습니다.
내가 한 일 :
프로젝트 속성 >> Java 빌드 경로 >> 소스
- '제거'옵션을 사용하여 비어 있던 원본 'src'폴더를 삭제했습니다.
- '폴더 추가'옵션을 사용하여 내 소스 .java 파일이 포함 된 소스를 추가했습니다.
이것은 오류를 해결했습니다.
Eclipse의 개요 사이드 바에서 메인 기능을 실행 해 볼 수 있습니다.
***
닫고 다시 엽니 다.
*** 이클립스에서 프로젝트. 때때로 연결 문제가 있습니다. 이것은 내 문제를 해결했습니다.
빠른 솔루션 :
먼저 패키지를 제외합니다. 소스 패키지 >> 빌드 경로 >> 제외를 마우스 오른쪽 버튼으로 클릭합니다.
그런 다음 다시 포함 : 소스 패키지를 마우스 오른쪽 버튼으로 클릭 >> 빌드 경로 >> 포함
해야 할 일은 Java 프로젝트를 생성하는 것입니다. 그러나이 파일을 해당 프로젝트의 패키지 파일에 넣어야합니다. 그렇지 않으면 동일한 오류가 발생합니다.
해당 코드는 유효합니다. scalac을 사용하여 직접 컴파일 해 보셨습니까? 또한 개체 이름처럼 파일을 "주소록"으로 모두 소문자로 지정 했습니까?
또한 어떤 이유로 이클립스가 메인 클래스를 "addressbook"대신 ".addressbook"으로 설정하는 것을 발견했습니다.
you should create your file by
selecting on right side you will find your file name,
under that will find src folder their you right click select -->class option
their your file should be created
Make sure that your .java file is present either in the str package, or in some other package. If the java file with the main function is outside all packages, this error is thrown.
Have faced the similar issue, resolved this by right clicking on the main method in the outline view and run as Java application.
I just had this problem too. The solution is to make sure eclipse created the project as Java project. Just create a new Java project and copy your class into the src folder (and import the eventual dependencies). This should fix the problem.
The correct answer is: the Scala library needs to before the JRE library in the buildpath.
Go to Java Buildpath > Order and Export and move Scala library to the top
I had this problem with a Java project that I imported from the file system (under Eclipse Helios). Here's a hint: the src code didn't seem to be compiled at all, as no "bin" directory showed up.
I had to create a Java project from scratch (using the wizard), then compare the .project
files of the non-working and working projects.
The project giving "Editor does not contain a main type" had this as the "buildSpec" in the .project file:
<buildSpec>
</buildSpec>
But the working project had this as the "buildSpec":
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
I copied this in, and the imported project worked.
I know my answer is for Java, but the same might be the issue for your Scala project.
May be the file you have created is outside the src(source) folder. Trying to call the class object(from the file located in the src folder) from the .java file outside the source folder results in the same error. Copy .java file to the source folder, then build it. The error will be gone.
I had the same problem. I had the main class out of the src package, in other folder. I move it in and correct folder and solved
run "eclipse -clean -refresh" from command line. This fixed the issue for me when all other solutions failed.
This could be the issue with the Java Build path. Try below steps :
- Go to project properties
- Go to java Build Path
- Go to Source tab and add project's src folder
This should resolve the issue.
If it is maven project please check the java file is created under src/main/java
If you are not getting please change the JRE path and create the java files in above folder structure
For me, in Eclipse 3.6, this problem occurs when my main method is not public. I caused the problem by having a main method like this:
static void main(String[] args)
The dubugger was unable to detect this by itself. I am pretty suprised Eclipse overlooked this.
In the worst case - create the project once again with all the imports from the beginning. In my case none of the other options worked. This type of error hints that there is an error in the project settings. I once managed to solve it, but once further developments were done, the error came back. Recreating everything from the beginning helped me understand and optimize some links, and now I am confident it works correctly.
Follow the below steps:
- Backup all your .java files to some other location
- delete entire java project
- Create new java project by right click on root & click new
- restore all the files to new location !!
File >> Import >> Existing Projects into Workspace >> Select Archive Filed >> Browse and locate file >> Finish. If its already imported some other way delete it and try it that way. I was having the same problem until i tried that.
One more thing to check: make sure that your source file contains the correct package declaration corresponding to the subdirectory it's in. The error mentioned by the OP can be seen when trying to run a "main type" declared in a file in a subdirectory but missing the package statement.
I have this problem too after I changed the source folder. The solution that worked for is just editing the file and save it.
'프로젝트 업데이트'를 시도하십시오. 이 작업을 수행하면 Java 응용 프로그램으로 실행 옵션이 나타납니다.
내 특정 'Hello World'의 경우이 문제의 원인은 내 main()
메서드가 Scala 내부에 있다는 사실 이었습니다 class
.
이 main()
메서드를 Scala 아래에 두었고 object
오류가 사라졌습니다.
object
Java 용어로 Scala 는 내부에 정적 멤버와 메소드 만있는 엔티티 이기 때문 입니다.
이것이 public static void main()
Scala 의 Java가 object
.
(Scala class
는 내부에 정전기를 포함하지 않을 수 있습니다)
참고 URL : https://stackoverflow.com/questions/1113729/editor-does-not-contain-a-main-type
'Programing' 카테고리의 다른 글
apt-get : 명령을 찾을 수 없습니다. (0) | 2020.09.07 |
---|---|
메타 프로그래밍을위한 Python 대 Ruby (0) | 2020.09.07 |
PHP에서 내 웹 사이트의 모든 쿠키를 삭제하는 방법 (0) | 2020.09.07 |
왜“우리”와“자신”의 의미가 git-svn으로 바뀌 었습니까? (0) | 2020.09.07 |
예외에서 전체 스택 추적을 인쇄하는 방법은 무엇입니까? (0) | 2020.09.07 |