Reputation: 22076
i need to convert a base64 value into string array so simply i have write this :
String s[] = new String[partyname.length];
for(int i=0;i<=partyname.length;i++)
{
byte[] bytes = Base64.decode(partyname[i], Base64.DEFAULT);
String string = new String(bytes, "UTF-8");
s[i] = string;
System.out.println("string is ::" + string+s[i]);
}
but i dont know why it raise null pointer error at s[i] = string;
line if i remove it then working fine so please help me out.
Upvotes: 0
Views: 484
Reputation: 1129
As said, s is null, I want to add another consideration:
The for loop should be: for(int i=0;i<partyname.length;i++)
instead of for(int i=0;i<=partyname.length;i++)
Upvotes: 1
Reputation: 11553
You need to create your String array that s references first. You have
String[] s = null;
So when you try to use s such as
s[i] = string;
Then there s is still null, and trying to get the i element of s gives you the null pointer.
From the rest of the code I think you want a String array with the same number of elements as party name, so you need
String[] s = new String[partyname.length];
Upvotes: 1
Reputation: 272687
Because s
is null.
You probably want this as the first line:
String[] s = new String[partyname.length];
Upvotes: 6