0

I am going to implement wizard with SWT / jface. When I run my program, I have the below error:

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)

The part of my code:

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

As seen in the code it has an error, even when the ReservationWizard() is empty. What should I do?

It has an error on the specified lines.

edit: When I created a display, I have the below error:

 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
B A
  • 71
  • 9
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Marvin Aug 20 '17 at 16:27
  • Where is the `Wizard` class defined? You may need to call `super()` inside the ReservationWizard constructor. – mattbdean Aug 20 '17 at 16:30

1 Answers1

1

You have not created a Display before calling your wizard. The first thing an SWT / JFace application has to do is create the display.

So you need:

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();
}
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks. when I do that. I have the error: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/commands/common/EventManager at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) I edited my post and added the full error. – B A Aug 20 '17 at 18:36
  • You need to include the `org.eclipse.core.commands` jar from Eclipse in the app build path to use the JFace wizard. – greg-449 Aug 20 '17 at 18:49