代码之家  ›  专栏  ›  技术社区  ›  B A

Java语言组织中的lang.NullPointerException。日食jface。资源JFaceResources。获取资源

  •  0
  • B A  · 技术社区  · 7 年前

    我将用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
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   greg-449    7 年前

    您尚未创建 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();
    }