Results 1 to 2 of 2
Thread: Little GUI question.
- 10-08-2011, 02:32 AM #1
Little GUI question.
Ok, so I have a JButton, when you you open this button, you choose a file(JFileChooser). But if you choose the "x" button(close), I get exception.
So, if user press exit or cancel while in the JFileChooser box, I get this error:Java Code:JButton lfile = new JButton ("Load File"); lfile.setPreferredSize (new Dimension (140, 40)); lfile.addActionListener (new ActionListener () { @Override public void actionPerformed (ActionEvent e) { JFileChooser fchooser = new JFileChooser (new File (".")); int option = fchooser.showOpenDialog(null); //If no file was choosen(user pressed cancel or exit button if (option == JFileChooser.APPROVE_OPTION) return; File inputFile = fchooser.getSelectedFile (); try { MainStuff.cry.setFilePath (inputFile); } catch (FileNotFoundException e1) { e1.printStackTrace(); } MainStuff.inputPath = inputFile.getAbsolutePath (); } });
So, how do I cancel the method in a better way?Java Code:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at pjjava.crypt.AbstractFileCrypting.setFilePath(AbstractFileCrypting.java:19) at pjgui.app.BaseFrame$1.actionPerformed(BaseFrame.java:92) 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$000(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)
-
Re: Little GUI question.
Why are you returning out of the method if the user chooses the approve option? Shouldn't that be != not == there? Also, you'll want to enclose all blocks, including single line if blocks, in curly braces.
Similar Threads
-
GUI question.
By ryainad in forum Advanced JavaReplies: 3Last Post: 04-02-2011, 02:47 AM -
Question concerning question marks and colons
By jim01 in forum New To JavaReplies: 17Last Post: 01-14-2011, 12:05 AM -
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
Question!
By anjogomez in forum Java AppletsReplies: 2Last Post: 02-21-2009, 03:24 AM -
Hello everyone and my first question
By htetnaing in forum New To JavaReplies: 3Last Post: 01-26-2009, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks