编译Java教程错误
问题描述:
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();
}
}
输出:编译Java教程错误
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> Organize Imports,然后保存更改。
答
首先,你将有相应的库添加到您的项目(SWT-GTK的x.y.jar你的情况)。
您的IDE将有可能为您计算适当的导入。
你的显示类在哪里?您需要添加导入语句。 – kosa 2012-08-16 18:14:51
您是否按照说明所述执行操作并在Java编辑器中右键单击并选择Source> Organize Imports,然后保存您的更改?此外,你需要确保适当的罐子在你的类路径中。 – 2012-08-16 18:15:17