Need help with NPE?
in
Programming Questions
•
10 months ago
Here is the code where it is happening:
- //Up in the global declarations:
- color[] colors;
- void setup(){
- //Stuff in here
- createColors();
- }
- void draw(){
- //Stuff in here
- }
- void createColors(){
- int var1 = height/50;
- int var2 = width/100;
- for(int i = 0; i < var2; i++){
- for(int j = 0; i < var1; j++){
- float r, g, b;
- r = random(255);
- g = random(255);
- b = random(255);
- color newColor = color(r, g, b);
- colors[i+j] = newColor;
- }
- }
- }
In line 26 of the above code, I get a NPE.
Instead of line 25 and line 26, I have tried the alternative options and I still get the same NPE:
- colors[i+j] = color(r, g, b);
And also manually:
- colors[i+j] = color(255, 255, 255);
If anyone could please point out my errors, I would much appreciate it!
Thank You
1