Results 1 to 3 of 3
  1. #1
    kaizen9001 is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Unhappy Having a problem with parsing

    Hi there, I'm new to this forum so I'll just give you as much information as possible. Sorry if I'm repeating myself or over-explaining anything.

    I'm trying to take a string value of a combobox and convert it into a Float. This float will then be used in another project (in the same package) to determine the width of a line that will be drawn. Essentially the user should be able to select a line thickness from the combobox and then when they draw, their line will be in that thickness.

    Here is the code for the combobox (in project 1)
    Java Code:
        
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            String item = (String)jComboBox1.getSelectedItem();
            myLineWidth.setMyLineWidth(Float.parseFloat(item));
            
        }
    My setter (in project 2)
    Java Code:
      
    public void setMyRadioButton(int i) {
            myRadioButton = i;
        }
    Being given a default value (project 2)
    Java Code:
    myLineWidth = new Float(8.0f);
    And then the "myLineWidth" variable being set to the number chosen from the combobox (project 2)
    Java Code:
    g2Buffer.setStroke(new BasicStroke(myLineWidth));
    The program runs fine, but when I try to change the value I get lots of errors in my console:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at CM3063.cw1.DrawFrame.jComboBox1ActionPerformed(Dra wFrame.java:136)
    at CM3063.cw1.DrawFrame.access$100(DrawFrame.java:21)
    at CM3063.cw1.DrawFrame$2.actionPerformed(DrawFrame.j ava:74)
    at javax.swing.JComboBox.fireActionEvent(JComboBox.ja va:1240)
    at javax.swing.JComboBox.setSelectedItem(JComboBox.ja va:567)
    at javax.swing.JComboBox.setSelectedIndex(JComboBox.j ava:603)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mou seReleased(BasicComboPopup.java:817)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEven tMulticaster.java:273)
    at java.awt.Component.processMouseEvent(Component.jav a:6263)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMo useEvent(BasicComboPopup.java:481)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    Any help would be greatly appreciated!
    Thanks

  2. #2
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    When you see a stack trace like that, start from the top and see where the error is occurring:
    Java Code:
    The program runs fine, but when I try to change the value I get lots of errors in my console: 
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at CM3063.cw1.DrawFrame.jComboBox1ActionPerformed(Dra wFrame.java:136)
    So I think the problem is in this callback:
    Java Code:
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            String item = (String)jComboBox1.getSelectedItem();
            myLineWidth.setMyLineWidth(Float.parseFloat(item));
            
        }
    Is it possible that myLineWidthor item is null at this point? You can put a check in that method to verify this.

  3. #3
    kaizen9001 is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default

    I did printlns for them both. mylinewidth is coming up as null and item is coming up as whatever i select in the combobox.
    Thanks for the reply!

Similar Threads

  1. Problem in parsing text
    By holy.water in forum New To Java
    Replies: 11
    Last Post: 02-19-2011, 06:19 PM
  2. String Parsing Problem
    By jamess in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 10:59 AM
  3. Problem with string parsing.
    By dc0m in forum New To Java
    Replies: 5
    Last Post: 08-31-2010, 07:25 PM
  4. Parsing Problem in Java
    By vidya in forum Advanced Java
    Replies: 4
    Last Post: 02-01-2010, 04:48 PM
  5. parsing problem
    By Pooja Deshpande in forum Advanced Java
    Replies: 4
    Last Post: 05-29-2008, 02:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •