René Beneš
René Beneš

Reputation: 468

Split returning null

Im making game plugin in java and Ive got problem with split function.

index = 0;
        int leng = a.length;
        while(index != leng){
            arr = a[index].split("|"); //this is line 158
            if(arr[1] == "blue"){
            blues[index]= arr[1];
            }else{
                reds[index] = arr[1];
            }
            index++;
        }

Im getting NullPointerException on line 158.
variable arr is just empty array.
Im printing variable "a" to make sure its not null.
"a" looks like this: 100 58 -9|red.
Can you help me? Thank you

Upvotes: 0

Views: 163

Answers (2)

Bernard
Bernard

Reputation: 7961

Are you sure that any a[index] itself is not null? Array a cannot be empty otherwise you wouldn't enter the while loop.

Upvotes: 0

MByD
MByD

Reputation: 137362

split receives a regular expression, so instead of arr = a[index].split("|");, do arr = a[index].split("\\|");

Upvotes: 4

Related Questions