Image pixels issue on android
in
Android Processing
•
5 months ago
Hi,
I am getting a Nullpointer exception from the following. Any idea why?
As you can see I have an if statement to make sure that the image is not null and it happens on first entry to the loop...
- int r=0,g=0,b=0;
- if(img!=null && img.width>-1){
- for(int px=0;px<img.width;px++){
- for(int py=0;py<img.height;py++){
- int loc = px + py*img.width;
- r+=red(img.pixels[loc]);
- g+=green(img.pixels[loc]);
- b+=blue(img.pixels[loc]);
- }
- }
- }
The error message is as follows:
- FATAL EXCEPTION: Animation Thread
- java.lang.NullPointerException
- at processing.test.sketchname.sketchname.function_name(sketchname.java:328)
- at processing.test.sketchname.sketchname.setup(sketchname.java:85)
- at processing.core.PApplet.handleDraw(Unknown Source)
- at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
- at processing.core.PApplet.run(Unknown Source)
- at java.lang.Thread.run(Thread.java:1019)
Thanks
1