Results 1 to 2 of 2

Thread: Combo Box Troubles

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Unhappy

    I have a combo box that looks like this:
    Code:
        
    //Combo Box
    JComboBox cboTestNum = new JComboBox();
    cboTestNum.addItem("1");
    cboTestNum.addItem("2");
    cboTestNum.addItem("3");
    cboTestNum.addItem("4");
    cboTestNum.setSelectedIndex(0);
    I put it on my panel and now I want to find out what item is selected and assign it to an integer variable...

    All I get is Null Pointer problems...

    How can I assign the selected item to a variable named test?
    Code:
    int test;
    test = Integer.parseInt("" + cboTestNum.getSelectedItem());
    is giving me errors...

    Thanks!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Is there a getSelectedItem() method? I know the selectedItem property represents the object currently select in the combo box. But looking through my books i dont see a getSelectedItem method......

    Where are the NullPointer Exception being generated?

Posting Permissions

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



Click Here to Expand Forum to Full Width