I have a char[] that I am attempting to append values to. However, at the line newStringAr[count] = ar[j][i], I am receiving an error: java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.Character.charValue()' on a null object reference.
When I changed my array to a Character[], this error was resolved, but then I was not able to convert my array to a string as shown in the last line of the code sample below. How can I resolve this issue?
Note that ar is a previously-defined array of Characters (Character[] not char[]).
int count = 0;
char[] newStringAr = new char[ch.length];
for (int i = 0; i < ar.length; i++) {
for (int j = 0; j < ar.length; j++) {
if (count<ch.length) {
newStringAr[count] = ar[j][i];
count++;
}
}
}
String out = new String(newStringAr);