0

Hi,

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 by __avd: Added [code] tags.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Janu Sam
0

Hi, this is happening because no values have been assigned to the array, and hence it is throwing NullPointerException. Assign individual values to all the elements in the array and try again

0

Hi, this is happening because no values have been assigned to the array, and hence it is throwing NullPointerException. Assign individual values to all the elements in the array and try again

Ya, Thank you... I found the mistake...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.