I'm trying to pick a random texture from a fodler placed in assets and use it but it's giving me errors. I'm doing so in the main game screen class
final File dir = new File("img");
Random rand = new Random();
File[] files = dir.listFiles();
File file = files[rand.nextInt(files.length)];
Image = new Texture(Gdx.files.internal(file.getPath()));
The error is
java.lang.NullPointerException: Attempt to get length of null array
to my knowledge this error should only be there if File[] files = dir.listFiles();
is null, and it isn't, currently two pictures are there. So what's happening?
I tried supplying the full path in the first line to img
folder but to no avail. Plus I don't want to supply the full path anyway, it will change from device to another.
files
? \$\endgroup\$/home/user/Documents/android/game/android/assets/img
and my code is in/home/user/Documents/android/game/core/src/com/game/MainGame.java
\$\endgroup\$