load directory of files from applet
in
Programming Questions
•
2 years ago
I'd like to export this sketch to an applet using 1.2.1:
https://binarymillenium.googlecode.com/svn/trunk/processing/oga_tile
but I get this error:
Exception in thread "Animation Thread" java.lang.NullPointerException
at oga_tile.loadTiles(oga_tile.java:35)
at oga_tile.setup(oga_tile.java:53)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
My code is trying to use the dataPath() function to load data that is in data/ in the original sketch, but now I'm not sure if it's supposed to be baked into the jar or I need to provide a data folder myself at the same directory the index.html is - but even with an external data dir I get the error above.
The code looks like this:
tiles = loadTiles(dataPath("tiles"));
...
PImage[] loadTiles(String path) {
File dir = new File(path);
PImage tiles[];
tiles = new PImage[dir.list().length];
for (int i = 0; i < dir.list().length; i++) {
println( dir.list()[i]);
try {
tiles[i] = loadImage(path + "/" + dir.list()[i]);
} catch (Exception e) {
tiles[i] = null;
}
}
return tiles;
}
Do I need to be listing directories differently from within an applet, do the File methods not work?
https://binarymillenium.googlecode.com/svn/trunk/processing/oga_tile
but I get this error:
Exception in thread "Animation Thread" java.lang.NullPointerException
at oga_tile.loadTiles(oga_tile.java:35)
at oga_tile.setup(oga_tile.java:53)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
My code is trying to use the dataPath() function to load data that is in data/ in the original sketch, but now I'm not sure if it's supposed to be baked into the jar or I need to provide a data folder myself at the same directory the index.html is - but even with an external data dir I get the error above.
The code looks like this:
tiles = loadTiles(dataPath("tiles"));
...
PImage[] loadTiles(String path) {
File dir = new File(path);
PImage tiles[];
tiles = new PImage[dir.list().length];
for (int i = 0; i < dir.list().length; i++) {
println( dir.list()[i]);
try {
tiles[i] = loadImage(path + "/" + dir.list()[i]);
} catch (Exception e) {
tiles[i] = null;
}
}
return tiles;
}
Do I need to be listing directories differently from within an applet, do the File methods not work?
1
