[Solved] Compiler keeps saying Array is Null (Android Studio)


The issue is here:

int [] NumArray;
element = NumArray.length -1

Details:
you declared NumArray but never initialize it until the constructor is called (this is 100% ok) but the next line you are trying to get NumArray.length of the non initialized array and that is the reason…

Solution:
place this line inside the constructor, it belongs to it

element = NumArray.length -1;

like

public Method(){
    NumArray = new int [length]
    element = NumArray.length -1;
}

2

solved Compiler keeps saying Array is Null (Android Studio)