loadImage() with Android causes fatal exception
in
Android Processing
•
5 months ago
So I'm trying to get a sketch for android load and then draw an image.
But when I run on my device, this happens:
- FATAL EXCEPTION: Animation Thread
- java.lang.IllegalArgumentException: File resources/cannon.png contains a path separator
- at android.app.ContextImpl.makeFilename(ContextImpl.java:1660)
- at android.app.ContextImpl.getFileStreamPath(ContextImpl.java:812)
- at android.content.ContextWrapper.getFileStreamPath(ContextWrapper.java:175)
- at processing.core.PApplet.sketchPath(Unknown Source)
- at processing.core.PApplet.createInputRaw(Unknown Source)
- at processing.core.PApplet.createInput(Unknown Source)
- at processing.core.PApplet.loadImage(Unknown Source)
- at processing.test.imagetest.ImageTest.setup(ImageTest.java:30)
- at processing.core.PApplet.handleDraw(Unknown Source)
- at processing.core.PGraphicsAndroid2D.requestDraw(PGraphicsAndroid2D.java:169)
- at processing.core.PApplet.run(Unknown Source)
- at java.lang.Thread.run(Thread.java:856)
And my code looks like this:
- PImage img;
- void setup ()
- {
- size(200, 200);
- img = loadImage("resources/cannon.png");
- }
- void draw ()
- {
- image(img, 0, 0, width, height);
- }
My file structure has a folder in the sketch's directory called "resources" with a file called "cannon.png" inside.
When I tried moving "cannon.png" right next to the (only) .pde file and changing line 6 to be:
img = loadImage("cannon.png");
I get a null pointer exception saying that "cannon.png" cannot be found.
What is going on and how can I get around this?
1