2010-02-16 5 views
0

Eclipse를 사용하여 Hello World SWT 응용 프로그램을 만들려고합니다. 모든 지시 사항을 따르고 결국 프로그램이 작동하지 않습니다.SWT 응용 프로그램이 작동하지 않는 이유는 무엇입니까?

이 내 코드입니다 :

import gnu.gcj.xlib.Display; 
import org.eclipse.swt.widgets.Shell; 


public class HelloWorldSWT { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setText("Hello world!"); 
     shell.open(); 
     while (!shell.isDisposed()) { 
     if (!display.readAndDispatch()) display.sleep(); 
     } 
     display.dispose(); 
    } 

} 

그리고 이것은 내 오류 메시지입니다 :

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The constructor Shell(Display) is undefined 
    The method readAndDispatch() is undefined for the type Display 
    The method sleep() is undefined for the type Display 
    The method dispose() is undefined for the type Display 

    at HelloWorldSWT.main(HelloWorldSWT.java:13) 

아무도 내가 잘못이 무엇인지 확인할 수있는 방법을 알고 있나요?

답변

8

잘못된 Display 클래스를 가져 오는 것 같습니다. 오른쪽 하나는이 일을해야 실행 클래스를 추가, 그것을 다시 가져 오기 SWT하는 PROJ를 만들 경로를 구축 확인 폴더에

org.eclipse.swt.widgets.Display 
+1

"import org.eclipse.swt.widgets.Shell;"을 "바꿀 때" "org.eclipse.swt.widgets.Display"에 의해 이클립스는 필자에게 갈등이 있음을 알린다. 내 코드의 첫 번째 줄을 제거했습니다 (import gnu.gcj.xlib.Display;). 그렇다면 내 프로그램을 실행하려고 할 때 여전히 몇 가지 오류 메시지가 있습니다. "main"스레드의 예외 java.lang.Error : 컴파일되지 않은 컴파일 문제 : \t 쉘을 유형으로 확인할 수 없습니다. \t 쉘을 유형으로 확인할 수 없습니다. at HelloWorldSWT.main (HelloWorldSWT.java:12) – Roman

+1

가져 오기를'org.eclipse.swt.widgets.Shell'로 가져오고'org.eclipse.swt.widgets.Display' 가져 오기를 추가해야합니다. –

0

청소 모든해야한다. 그렇지 않은 경우 마우스 오른쪽 버튼을 클릭하고 정리를 클릭 한 다음 소스를 클릭합니다. 가져 오기를 구성하고 다시 실행하십시오. 라이브러리에 더

swt.dll

에러하지 않는 경우, 작동해야 라이브러리 경로에 모든

swt.dll

를 복사합니다. 지금 일해야한다.

+0

좋은 직장에서 일하세요. – alex

0

동일한 실수를했습니다. 내 문제는 두 번째 단계입니다 : "org.eclipse.swt"가져 오기를 선택했습니다. 대신 운영 체제에 맞는 올바른 것을 선택해야합니다. 제 경우에는 "org.eclipse.swt.win32.win32.x86"입니다. 이 작업을 완료하면 튜토리얼의 나머지 단계가 예상대로 작동합니다.

위의 답변은이 자습서를 완료하는 것보다 더 많은 지식이 필요하다고 가정 할 수 있습니다.

관련 문제