0
votes

I created a desktop game in eclipse using Libgdx. The game runs great in eclipse, however the FileHandle list() method doesn't work when exported to a jar file. I used the following lines of code:

songFiles = Gdx.files.internal("./bin/" + "songs/").list();
System.out.println(songFiles[0]);

Again, in eclipse it prints the file location.However when exported to a jar, I get a java.lang.ArrayIndexOutOfBoundsException: 0 error.

Cannot export default Java libGDX project as a jar from Eclipse looks similar to the issue that I am having

2
No, the problem is that the list() method doesn't operate the same as it does in eclipse. I think that it is something to do with the file structure when a project is exported to a jar file. - Will Roberts
I was about to write something like this but can't figure out what exactly the problem is. - Gürtuğ Güngör
To quote the javadocs: "On the desktop, an Files.FileType.Internal handle to a directory on the classpath will return a zero length array.". libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/…. Or to quote the wiki: "Listing of internal directories is not supported on Desktop." github.com/libgdx/libgdx/wiki/…. - Xoppa

2 Answers

0
votes

It says you created the list or array but u didn't initialize it with length. That's why you have 0 at the end of error message.

0
votes

Since the list() method cannot be used on desktop applications, I will solve this issue by reading and writing the filenames in the songs directory to a text file.