getResources上的java

getResources上的java

我将使用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.access$100(URLClassLoader.java:73)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
 at java.net.URLClassLoader$1.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.access$100(URLClassLoader.java:73)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
 at java.net.URLClassLoader$1.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();
}

关于java - org.eclipse.jface.resource.JFaceResources.getResources上的java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45784350/

10-10 07:52