2016-07-06 3 views
0

첫 번째 Eclipse Java 프로젝트를 실행하려고하지만 어떤 이유로 Eclipse가 main을 찾을 수 없습니다.Eclipse가 기본 클래스를 찾을 수 없습니다.

새로운 Java 실행 구성을 만들고 프로젝트의 소스 파일 디렉토리를 클래스 경로 탭의 사용자 항목에 추가했습니다. 그런 다음 기본 탭 아래의 main 클래스 필드에 기본 클래스 DisplayDeck을 추가했습니다. 프로젝트를 실행할 때 다음 오류가 발생합니다. 뭔가 다른 내가 발견 ... 내가 여기에 몇 가지 비슷한 질문을 읽은하지만, 그 질문에 대한 해결책으로 작동 할 것 같다

package cards; 

public class DisplayDeck { 
    static void main(String[] args) { 
     Deck cardDeck = new Deck(); 
     for (int i = 0; i < 4; i++) { 
      for (int j = 0; j < 13; j++) { 
       card tempCard = cardDeck.getCard(i, j); 
       System.out.format("%s of %s", tempCard.rankToString(tempCard.getRank()), tempCard.suitToString(tempCard.getSuit())); 
      } 
     } 
    } 
} 

하면됩니다 : 여기

Error: could not find or load main class DisplayDeck.

내 코드입니다 빌드 구성에서 main 클래스 필드 옆에있는 검색 버튼을 선택하면 listView에서 선택할 수있는 클래스가 없습니다.

+0

당신은 주요 방법이 있나요? 코드보기 – Li357

+0

코드 붙여 넣기? – phil652

+0

패키지 카드; public class DisplayDeck { \t statick void main (String [] args) { \t 갑판 cardDeck = 새로운 갑판(); \t \t 가 (나는 4 <; I = 0 int로 난 ++) {위한 \t \t (INT의 J = 0; J <13; J ++) { \t \t \t 카드 tempCard = cardDeck.getCard (I, J) ; \t \t \t tempCard.suitToString (tempCard.getSuit())); System.out.format ("% s of % s", tempCard.rankToString (tempCard.getRank()); \t \t \t \t \t \t \t \t \t} \t \t은} \t} \t} – user2094257

답변

2

코드 스 니펫에는 static void main(String[] args)이 아니고 public static void main(String[] args)이 아닙니다. 이것이 주를 찾을 수없는 이유입니다. http://www.cs.princeton.edu/courses/archive/spr96/cs333/java/tutorial/java/anatomy/main.html에서

:

The method signature for the main() method contains three modifiers: public indicates that the main() method can be called by any object. Missing Page covers the ins and outs of access modifiers supported by the Java language: public, private, protected, and the implicit, friendly. static indicates that the main() method is a class method. Class Members vs. Instance Members later in this lesson talks in more detail about class methods and variables. void indicates that the main() method has no return value. The main() method in the Java language is similar to the main() function in C and C++. When you execute a C or C++ program, the runtime system starts your program by calling its main() function first. The main() function then calls all the other functions required to run your program. Similarly, in the Java language, when you execute a class with the Java interpreter, the runtime system starts by calling the class's main() method. The main() method then calls all the other methods required to run your application. If you try to run a class with the Java interpreter that does not have a main() method, the interpreter prints an error message. For more information see Troubleshooting Interpreter Problems .

Arguments to the main() Method

As you can see from the code snippet above, the main() method accepts a single argument: an array of Strings.

public static void main(String args[]) 
+0

고마워요. 이제 잘 작동합니다. C++에서 명령을 내리면 각 함수/필드 앞에 액세스 수정자를 넣어야하는 것이 이상한 것처럼 보입니다. – user2094257

+0

향후 소스를 올바르게 특성화하고 인용하십시오. http://stackoverflow.com/help/referencing을 참조하십시오. – Matt

관련 문제