在Java教程中编译错误

时间:2012-08-16 18:13:22

标签: java compilation

public class HelloWorldSWT {

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();
}

}

输出:

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

    at HelloWorldSWT.main(HelloWorldSWT.java:10)

我是Java的新手,我尝试了这些但仍然没有工作:

指令告诉我:你会得到编译错误。右键单击Java编辑器,然后选择Source>组织导入,然后保存您的更改。

1 个答案:

答案 0 :(得分:1)

首先,您必须在项目中添加适当的库( swt-gtk-x.y.jar )。

您的IDE将有可能为您计算正确的导入。