java.lang.NullPointerException 在 org.eclipse.jface.resource.JFaceResources.getResources

java.lang.NullPointerException at org.eclipse.jface.resource.JFaceResources.getResources

我打算用 SWT / jface 实现向导。当我 运行 我的程序时,出现以下错误:

Exception in thread "main" java.lang.NullPointerException
at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:209)
at org.eclipse.jface.resource.JFaceResources.getImageRegistry(JFaceResources.java:402)
at org.eclipse.jface.wizard.Wizard.<init>(Wizard.java:105)
at mypackage.ReservationWizard.<init>(ReservationWizard.java:21)
at mypackage.ReservationWizard.main(ReservationWizard.java:69)

我的部分代码:

public class ReservationWizard extends Wizard {

**public ReservationWizard() {**

//    setWindowTitle("Hotel room reservation wizard");
 //   setNeedsProgressMonitor(true);
 //  setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(null, "Unknown.jpg"));
}
...
    public static void main(String[] args) {
 **ReservationWizard wizard = new ReservationWizard();**
 WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);

 dialog.setBlockOnOpen(true);
    dialog.open();
 } 
}

如代码所示,它有错误,即使 ReservationWizard() 为空也是如此。我该怎么办?

指定行有错误。

编辑: 当我创建一个显示时,出现以下错误:

 at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
 at java.net.URLClassLoader.access0(URLClassLoader.java:73)
 at java.net.URLClassLoader.run(URLClassLoader.java:368)
 at java.net.URLClassLoader.run(URLClassLoader.java:362)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
 at java.net.URLClassLoader.access0(URLClassLoader.java:73)
 at java.net.URLClassLoader.run(URLClassLoader.java:368)
 at java.net.URLClassLoader.run(URLClassLoader.java:362)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 at org.eclipse.jface.resource.JFaceResources.getFontRegistry(JFaceResources.java:340)
 at org.eclipse.jface.window.Window.createShell(Window.java:508)
 at org.eclipse.jface.window.Window.create(Window.java:429)
 at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096)
 at org.eclipse.jface.window.Window.open(Window.java:792)
 at mypackage.ReservationWizard.main(ReservationWizard.java:76)
Caused by: java.lang.ClassNotFoundException:    org.eclipse.core.commands.common.EventManager
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 ... 30 more

在调用向导之前,您还没有创建 Display。 SWT / JFace 应用程序必须做的第一件事是创建显示。

所以你需要:

public static void main(final String [] args)
{
  // Create the display
  Display display = new Display();

  ReservationWizard wizard = new ReservationWizard();
  WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);

  dialog.setBlockOnOpen(true);
  dialog.open();
}