I'm getting a Null pointer access: The variable 'numbers' can only be null at this location
error from intellisense with the following code. (Errors marked)
public static int isOne(int incoming){
String original = Integer.toString(incoming);
int length = original.length();
int i;
int numbers[] = null;
for(i = 0; i < length; i++){
String worker = Character.toString(original.charAt(i));
int workInt = Integer.parseInt(worker);
/* HERE */ numbers[i] = workInt;
System.out.print(i + "=" + workInt + ","); /* this line just tests it */
}
int z;
int sum = 0;
int thisNumber = 0;
for(z = 0; z < length; z++){
/* HERE */ thisNumber = numbers[z];
thisNumber = thisNumber * thisNumber;
sum = sum + thisNumber;
}
return 0;
}
When running the code, the console gives an exception on the first error. LogCat gives nothing.
Intellisense give the suggestion of an @suppress
for the two errors.
I really don't have a clue, but I think it might be at the point where I initialise 'numbers'.
Thanks for any help.
numbers
. You set it to null, which unsurprisingly causes a null pointer exception later on. – biziclop Mar 30 at 18:21