Null Pointer Exception Help
in
Programming Questions
•
7 months ago
I am writing a fairly simple sketch.
15" MacBook Pro, 2.4GHz Intel Core i5, OS X v.10.2.8 Mountain Lion,
QuickTime Player v.10.2, Processing v. 1.5.1 and v.2.0b8, Arduino Uno, Nano v.3.
Here is the relevant code:
float [] deg;
void setup() {
size (1024, 578);
background(255);
float [] deg = new float[28];
for (int i = 0; i < deg.length; i++) {
deg[i] = 0.0;
}
}
void draw () {
background(255);
smooth();
// first row
pushMatrix();
translate(90, 85);
rotate(radians(deg[0])); // this line is flagged with Null Pointer Exception
rect(-45, -45, 90, 90);
fill(255);
popMatrix();
I thought, since I am not using a class, the lines
float [] deg = new float[28];
for (int i = 0; i < deg.length; i++) {
deg[i] = 0.0;
}
would be sufficient to prevent the deg array from having any null values.
Why am I getting this error?
Thanks,
George
15" MacBook Pro, 2.4GHz Intel Core i5, OS X v.10.2.8 Mountain Lion,
QuickTime Player v.10.2, Processing v. 1.5.1 and v.2.0b8, Arduino Uno, Nano v.3.
1