Declaring static character array
I can't figure out how to declare a static two dimensional array.
I tried...
static char [][] array = new char [numberOfRows][numberOfColumns];
static final char [][] array = new char [numberOfRows][numberOfColumns];
can't figure it out. Please help. Thanks!:cool:
Re: Declaring static character array
..and what happened when you tried either of those in your code? Post an SSCCE with the full errors you receive.
Re: Declaring static character array
You may need to initialize the numberOfRows and numberofColumns variables first and give them values or else you will get an ArrayIndexOutOfBounds error when you try to access them...
static int numberOfRows = 10;
static int numberOfColumns = 20;
static char [][] array1 = new char [numberOfRows][numberOfColumns];
static final char [][] array2 = new char [numberOfRows][numberOfColumns];
Re: Declaring static character array
I get illegal start of expression and other wierd errors saying the array cannot be found, but it says them on lines that don't even have code on them???
Re: Declaring static character array
Post an SSCCE (see my signature if you don't know what this is)...we can guess at what's wrong, but guesses are just that.
Re: Declaring static character array
You are trying to declare/initialize the array inside a method. Perhaps you should review how instance and class variables should be declared:
Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)