Dave Jones
Dave Jones

Reputation: 193

SWT in eclipse Java JDE not working

When I input the following Java code into eclipse, it returns an error. I am told by the eclipse tutorials that this should work. What am I doing wrong? This is a picture of my code.

import org.eclipse.swt;
public class SWTHELLOWORLD{
      public static void main(String[] args){
           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();
     }
}

When I run as a java application, it returns this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Display cannot be resolved to a type
    Display cannot be resolved to a type
    Shell cannot be resolved to a type
    Shell cannot be resolved to a type

Upvotes: 0

Views: 871

Answers (2)

Matt  Watson
Matt Watson

Reputation: 5317

You are not importing the Display and Shell classes.

You should add the following imports to the top of your class:

import org.eclipse.swt.widgets.Display
import org.eclipse.swt.widgets.Shell

Just importing org.eclipse.swt will not import all the classes that you need.

Upvotes: 1

M. Kneißl
M. Kneißl

Reputation: 1

You used

public static void main (Strings[] args)

while the correct way of putting it would be

public static void main (String [] args)

Mind that it is String without the 's' in the end.

Upvotes: 0

Related Questions