Arin Arin - 1 year ago 74
Java Question

Array NullPointerException?

Ok. I don't get why my code is reporting a NullPointerException, but I've been here for quite a while trying to figure it out.

And no,

is not

Edit: That was a mistake on my part, it was null (I didn't see the order I was running the functions.

Here is my code:

public String[] files;

private void updateRefs(String filepath) {
try {
files[scr] = filepath; //NullPointerException???
} catch ( Exception e ) {

Answer Source

You have to new it, otherwise it is null:

String[] files = new String[10]; //or whatever size you need