Reputation: 131078
I am trying to create a Hello World SWT application using Eclipse. I follow all instructions and in the end my program does not work.
This is my code:
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();
}
}
And this is my error messages:
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)
Does anybody know how I can check what is wrong?
Upvotes: 0
Views: 6055
Reputation: 2591
I made the same mistake. My issue was on the second step: I selected to import "org.eclipse.swt". Instead, you must select the correct one for your operating system. In my case, this was "org.eclipse.swt.win32.win32.x86". Once you've done this, the rest of the steps in the tutorial should work as expected.
The answers above, while correct, may assume a bit more knowledge than most completing this tutorial will have.
Upvotes: 0
Reputation: 1
Clean all in your folder, do it again, import swt create proj, check build path add class, run this should work. If not , right click , click clean up, click source... organize imports, run again. Should work, if error no
swt.dll
in your library, copy all
swt.dll
to your library path. Should work now.
Upvotes: 0
Reputation: 383
I think you're importing a wrong Display class. The right one should be
org.eclipse.swt.widgets.Display
Upvotes: 8