Reputation: 151
I want to store 1 to 110 in string array variable, when i tried am getting null pointer exception.
String age[];
for(int i=0;i<=101;i++){
age[i]=Integer.toString(i);
}
Upvotes: 0
Views: 4975
Reputation: 22066
You got error because you haven't initialized it :
String[] age = new String[111];
Upvotes: 1
Reputation: 24021
try this:
String[] age = new String[102];
String.valueOf(int value);
Upvotes: 2
Reputation: 25755
You'll need to initialize the String-array first:
String[] age = new String[110];
Upvotes: 4
Reputation: 9380
You have to create the String array first:
String[] age = new String[111];
Upvotes: 1