For loop not executing in the second run, why?
in
Programming Questions
•
2 years ago
There is an error in the following code.
At first all three loops are executed, but in the second run of the outer loop the middle loop in line 6 isnt executed.
The error message is:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.Main.getColor(Main.java:87)
at processing.Main.setup(Main.java:46)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
At first all three loops are executed, but in the second run of the outer loop the middle loop in line 6 isnt executed.
The error message is:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.Main.getColor(Main.java:87)
at processing.Main.setup(Main.java:46)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
- private int[] getColor(PImage[] pics) {
- long[] color = new long[pics.length];
- int[] c = {0};
- for(int i = 0; i < pics.length; i++) { //Schleife geht einzelne Bilder durch
- println("i = " + i);
- for(int x = 0; x < pics[i].width; x++) { //2 Schleifen für die beiden Bildachsen
- println("x = " + x);
- for(int y = 0; y < pics[i].height; y++) {
- println("y = " + y);
- color[i] = color[i] + (long) red(pics[i].get(x, y));
- println("color[i] = " + color[i]);
- }
- }
- color[i] = color[i] / (pics[i].width * pics[i].height); //Aus Summe wird der Durchschnitt berechnet.
- println("Durchshnitt: color[i] = " + color[i] + ", " + col);
- }
- for(int i = 0; i < color.length; i++) {
- c[i] = (int) color[i];
- println("c[i] = " + c[i]);
- }
- return c;
- }
1