0

I'm trying to create a java window which displays a PHP login file using JEditorPane and JFrame. Actually displaying the PHP file part works out, however when I try to submit the user info and login in, which should redirect the user to another PHP file I get the following error:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.html.FormView.submitData(Unknown Source)
at javax.swing.text.html.FormView.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Looking at the error it seems to be something going wrong within javax.swing and after looking on the web I haven't been able to find anyone with similar issues. My question is that is this something I did incorrectly or is it an issue, and if so is there some sort of work around?

Source:

public class Main {

    public static void main(String arg[]) {
        Main.load();
    }

    public static void load() {
        JEditorPane jep = new JEditorPane();
        jep.setEditable(false);

        try {
            //Display chosen URL
            jep.setPage(URL);

        } catch (IOException e) {
            //Display error message
            jep.setContentType("text/html");
            jep.setText("<html>Could not load page, please try again later.<html>");
        }

        JScrollPane scrollPane = new JScrollPane(jep);
        JFrame f = new JFrame("Test HTML");                 //Create a window for the pane
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(scrollPane);
        f.setSize(325, 165);
        f.setVisible(true);                                 //Display the window

    }
}

Any help or advice would be much appreciated.

Thanks!

  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – DavidPostill Sep 14 '14 at 20:53
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – DavidPostill Sep 14 '14 at 20:54
  • @DavidPostill In that specific post they talk about the user's code creating Null Pointer Exceptions. In my case it appears that the error is coming within the Java language and my question was is this a known thing with fixes or work arounds. After looking around on the web I couldn't find any examples of this happening to anybody else. – AndrewBennett Sep 17 '14 at 16:38
  • That's why we ask for a **complete** (Complete – Provide all parts needed to reproduce the problem) example. With this we can run your code and see what might be going wrong. Please provide the rest of your code (not just random snippets) – DavidPostill Sep 17 '14 at 16:42
  • @DavidPostill Done. I did basically post the complete code excluding the main function calling for the window to be loaded – AndrewBennett Sep 17 '14 at 16:50
  • Your code does **not** compile. Missing imports. URL is not defined. How can we run it?! – DavidPostill Sep 17 '14 at 16:57

0 Answers0