PHP&JEditorPane:java.lang.NullPointerException
我正在尝试创建一个java窗口,它使用JEditorPane和JFrame显示一个PHP登录文件。实际上,显示PHP文件部分是可行的,但是当我尝试提交用户信息并登录时,这会将用户重定向到另一个PHP文件,我得到以下错误:PHP&JEditorPane:java.lang.NullPointerException,java,webpage,jeditorpane,Java,Webpage,Jeditorpane,我正在尝试创建一个java窗口,它使用JEditorPane和JFrame显示一个PHP登录文件。实际上,显示PHP文件部分是可行的,但是当我尝试提交用户信息并登录时,这会将用户重定向到另一个PHP文件,我得到以下错误: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.text.html.FormView.submitData(Unknown Source) at j
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)
查看错误,javax.swing中似乎出现了一些问题,在查看web之后,我还没有找到任何有类似问题的人。我的问题是,这是我做得不对的事情,还是一个问题,如果是的话,有什么解决办法吗
资料来源:
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
}
}
任何帮助或建议都将不胜感激
谢谢 寻求调试帮助的问题可能重复为什么此代码不起作用?必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅。@DavidPostill在那篇特定的文章中,他们讨论了用户创建空指针异常的代码。在我的例子中,错误似乎来自Java语言,我的问题是这是一个已知的修复或解决方法。在网上浏览之后,我找不到任何其他人发生这种情况的例子。这就是为什么我们要求提供完整的-提供重现问题示例所需的所有部分。有了它,我们可以运行您的代码并查看可能出现的问题。请提供代码的其余部分,而不仅仅是随机的snippets@DavidPostill完成。我基本上发布了完整的代码,不包括调用加载窗口的主函数