if (event.getSource() == openDoc) {
state = fileChooser.showOpenDialog(GUI); //This is line 112
if(state == JFileChooser.APPROVE_OPTION)
doc = fileChooser.getSelectedFile();
try {
FileReader in = new FileReader(doc);
BufferedReader out = new BufferedReader(in);
while ((line = out.readLine()) != null)
document.append(line + "\n");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at SpellCheckerGUI.actionPerformed(SpellCheckerGUI.java:112)
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$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(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.AccessControlContext$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)
The goal is to have a gui that has two "open" buttons. One to open a dictionary (list of words) and another to open text document that you make. The program is going to be a low end spell checker. My problem is I dont understand why I am getting a null pointer error. I read the .showOpenDiaglog() oracle page and I believe the JFrame component GUI should work as the parrent component so I am not sure why I am getting this error.
This segment of code it under the action listener method I am implementing in the GUI construction class. If the "Open DOc" button is pressed it will bring up the open dialog and allow the user to select a document. Once selected it is read into the filereader and appeneded to a jtextframe named document so that it can be viewed.
Any help would be much obliged.
This post has been edited by BigD959919: 07 December 2012 - 12:34 PM

New Topic/Question
Reply



MultiQuote



|