In my application, I am creating a string array in a method. Each time I call that method this array will get created and also a null pointer exception is showing when I use the Arrays.sort() method.
My method is like this...
int count = getTotalXMLCount(); envArray = new String[count]; /* code for adding the elements into the array from a file */ Arrays.sort(envArray, String.CASE_INSENSITIVE_ORDER); for (int i = 0; i < envArray.length; i++) variableCombo.addItem(envArray[i]);
First calling it works perfectly. But the second calling, it shows the exception
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source) at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source) at java.util.Arrays.mergeSort(Unknown Source)
In my conclusion it is due the line:
envArray = new String[count];
How can I delete this array during the second time. Can anybody help me in this issue pls...? Its urgent....
THANKS in Advance....
Edited 6 Years Ago by __avd: Added [code] tags.