Whenever I run my game from my IntelIJ IDEA the game runs fine. It finds every folder and every asset in there. But whenever I build my game with :desktop:dist and run it it will not see the folder I try to open as a folder and it will have 0 contents.

This is the code I use to open the folder:

        FileHandle mapFolder = Gdx.files.internal("maps");


    for (FileHandle entry : mapFolder.list()) {
        System.out.println("something is in");
        maps.add(new Map(entry.toString()));


The length it prints is 0. It does not print something is inso im fairly sure this is not working.

Whenever I try Gdx.files.classpath I get this error: Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Cannot list a classpath directory: maps

For clarification: It's a desktop only project. So no android.

I cannot figure it out, and I've looked at a lot of topics to try and fix this issue.


2 Answers 2


Just like the error says, you can not list all assets in a classpath FileHandle. The reason you're seeing this error even though you're using an internal file handle is because internal files are added to the .jar when the game is built (where else would they go?) and as such they must be added to the classpath to be readable. This is also the reason you can't write to an internal file, since internal files are converted to classpath files when the jar is built, and you can not edit classpath files.

Since you know all the files in the classpath at runtime you are expected to simply manually list them:

final String[] files = { "map1", "map2", ... };
final FileHandle[] handles = Stream.of(files).map(Gdx.files::internal);

If you want to be able to actually list contents of a file handle it has to be external or local. An external file is just any file on the user's computer. A local file is the same as external, except that the source directory is the same folder that your game's jar is inside. E.g. if your jar is inside C:/Program Files/MyAwesomeGame/game.jar then all local files would be relative to C:/Program Files/MyAwesomeGame/. This is especially useful when you want files to be editable, e.g. configuration files and save files.


Try to rebuild the project. Maybe it is corrupted.

Try creating again the folder and it's contents. I saw a guy with a similar problem and he said creating everything again worked.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .