I am passing an int array from one class to another but am getting an error when I try to access values from it. I have no idea why, hopefully someone can enlighten me?
Here's the first class that calls the second:
public class ConvertToGrid extends Activity{
DrawGrid v;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...code...
int[] binArray = {Color.RED, Color.WHITE, Color.YELLOW, ...};
v = new DrawGrid(this, binArray);
setContentView(v);
}}
This calls my DrawGrid View:
public class DrawGrid extends View{
private int[] binary;
public DrawGrid(Context context) {
super(context);
}
public DrawGrid(Context context, int[] inBinary) {
super(context);
binary = inBinary.clone();
}
int sq00c = binary[0];
...etc}
What am I doing wrong such that it cannot access this int array called binary? If I move the int array into DrawGrid it accesses the cells without any trouble, but passing it through with my construct seems to make it inaccessible. In case anyone asks, I can't just define the array in DrawGrid as it is defined by the code in ConvertGrid.
Perhaps I am going about this in the wrong way and there is a better way to pass the int array? Thanks
Edit:
LogCat:
E/AndroidRuntime(12035): FATAL EXCEPTION: main
E/AndroidRuntime(12035): java.lang.RuntimeException: Unable to start activity ComponentInfo{bras2756.ox.ac.uk.colourgrid/bras2756.ox.ac.uk.colourgrid.ConvertToGrid}: java.lang.NullPointerException