This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 212750 - Null Exception
Summary: Null Exception
Status: RESOLVED INVALID
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.0.1
Hardware: PC Windows 7
: P1 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-20 13:15 UTC by geniussy
Modified: 2012-05-21 09:07 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description geniussy 2012-05-20 13:15:29 UTC
Let's say we have two JComboBox (1 and 2) and jComboBox1's got already a set of String elements.
In the stateChanged methof (i dont remember the exact name of the listenner method), those lines will create an Null Exception:

jComboBox1.removeAllItems();
jComboBox2.addItem(jComboBox1.getSelectedItem().toString());

However, i fixed it by typing:

jComboBox1.removeAllItems();
jComboBox2.addItem((String)jComboBox1.getSelectedItem());

But, normally, toString() converts in a String format...!
Comment 1 Jan Stola 2012-05-21 09:07:25 UTC
> jComboBox1.removeAllItems();
> jComboBox2.addItem(jComboBox1.getSelectedItem().toString());

This code snippet has no sense. You remove all items from jComboBox1 and then (when there are no items there) you ask for the selected item of jComboBox1. Not surprisingly the selected item (i.e., jComboBox1.getSelectedItem()) is _null_ in such case. Therefore, NullPointerException is thrown when you attempt to invoke toString() on the returned value.

Note that besides having no sense this code snippet has nothing to do with NetBeans IDE. It is a problem in your code => I am closing this issue as invalid.