Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
almost done
Victoria Preston
Ranch Hand
Posts: 106
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm trying to get this gui to work, but my listeners are not working. My program is just crashing. Can someone look at it and tell me where I am going wrong.Here are my listeners
private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { String value = input.getText(); if(value.equals(null)) { String name = chooser.getSelectedFile().getName(); Scanner sc = null; try { sc = new Scanner(new File(name)).useDelimiter("\\.*"); } catch (FileNotFoundException e2) { System.out.println("File Not Found"); } Parser p = new Parser(); try { int val = p.parseExpr(sc); String myString = Integer.toString(val); output.setText(myString); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (Throwable e6) { e6.printStackTrace(); } } else{ Scanner sc = new Scanner(value).useDelimiter("\\.*"); Parser p = new Parser(); try { int val = p.parseExpr(sc); String myString = Integer.toString(val); output.setText(myString); } catch (Throwable e1) { e1.printStackTrace(); } } } } private class BrowseListener implements ActionListener { public void actionPerformed(ActionEvent e3) { chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(boxes); if(returnVal == JFileChooser.APPROVE_OPTION) { String myString = chooser.getSelectedFile().getName(); file.setText(myString); } } }
Michael Dunn
Ranch Hand
Posts: 4632
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
you should
post the error messages, but this part is wrong
if(value.equals(null))
as 'value' is the return from getText(), it could be empty, not null
if(value.equals(""))
if checking for null, it would be
if(value == null)
Victoria Preston
Ranch Hand
Posts: 106
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I found that error you saw just a minute ago. But it still doesn't work and here are the error messages
java.lang.NullPointerException at Parser.getToken(Parser.java:14) at Parser.parseExpr(Parser.java:49) at ParserGUI$ButtonListener.actionPerformed(ParserGUI.java:79) 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.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
David O'Meara
Rancher
Posts: 13459
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
firstly, "almost done" is not a useful topic at all. You should browse the pointers on asking questions on the Ranch as it will help you get answers.
You should print the value of "sc" each time before using it. I am not sure you re getting the behaviour you expect.
Victoria Preston
Ranch Hand
Posts: 106
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
what do you mean I should print it out
David O'Meara
Rancher
Posts: 13459
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
sc = Scanner etc... System.out.println("sc is: "+sc);
If it prints out "sc is null" you have found your problem.
Victoria Preston
Ranch Hand
Posts: 106
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I found my problem thank you
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Prompting the user whether to close the JFrame
Onchange JCombobox
listeners
I useDelimiter \t(ab) with my Scanner, but it splits around spaces
Scanner is skipping
More...