More trouble with classes and arrays
Okay, I got this file:
globals.java:
Code:
public class globals {
static public frame frames[] = new frame[maxFramesAllowed]; // Holds the grid data, maximum of 1000 frames right now
static public class frame {
public cell cells[] = new cell[maxCellsAllowed];
public char nextFreeCell = 0;
public char delay = 1;
public frame() {
// nothing
}
public frame(int frameDelay) {
delay = (char) frameDelay;
}
public frame(char frameDelay) {
delay = frameDelay;
}
}
static public class cell {
public char x;
public char y;
public char value;
public cell(int xVal, int yVal, int val) {
x = (char) xVal;
y = (char) yVal;
value = (char) val;
}
public cell(char xVal, char yVal, char val) {
x = xVal;
y = yVal;
value = val;
}
}
}
When I ran it with the regular portion of my program, I got errors about null pointers/objects.
So iIcreated this program to test the class:
TEST_globals.java
Code:
public class TEST_globals {
public globals g;
public static void main(String argv[]) {
for (int i = 0; i < 5; i++) {
globals.frames[i] = new globals.frame(i * 2);
System.out.println("Delay for frame[" + i + "]: " + globals.frames[i].delay);
for (int j = 0; j < 5; j++) {
System.out.println("\tFor frame[" + i + "], next free cell at[" + globals.frames[i].nextFreeCell + "]");
globals.frames[i].cells[globals.frames[i].nextFreeCell] = new globals.cell(j, j, i * j);
globals.frames[i].nextFreeCell++;
}
}
}
}
The result:
http://oi51.tinypic.com/2lcmi9t.jpg
Please help. :(