2016-12-06 108 views
0

当我将以下Java代码输入到eclipse中时,它会返回一个错误。日食教程告诉我,这应该起作用。我究竟做错了什么? This is a picture of my codeEclipse中的SWT Java JDE不工作

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

当我作为一个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 
+0

我正在运行windows 10. –

+3

请不要将文本作为图像发布。将您的代码和错误消息粘贴到您的问题中(并将其格式化以使其可读)。针对你的问题:这个类被称为'String'而不是'Strings'。此外,它看起来像你根本没有进口。 –

+2

您确实需要阅读Java基础知识。错误信息也很清楚。你缺少进口。 – Baz

回答

1

您没有导入Display和Shell类。

您应该添加以下进口类的顶部:

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

只导入org.eclipse.swt将不会导入你需要的所有类。

0

您使用

public static void main (Strings[] args)

,同时把它的正确的方法是

public static void main (String [] args) 

请注意,它是最终没有's'的字符串。

+0

我这样做,我得到这个错误:例外在线程“主要” java.lang.Error的:未解决的编译问题: \t显示解决不了的类型 \t显示解决不了的类型 \t壳牌不能解析为 \t Shell无法解析为 –

+0

Matt Watson的答案是正确的。加入 –

+0

对不起。添加 导入org.eclipse.swt.widgets.Display 导入org.eclipse.swt.widgets.Shell 到您的导入,它应该工作。 –