[LibGDX] Gdx.files.local doesn't seem to be finding my files.

Hey guys
This is probably a really simple issue and I might have just overlooked something really simple but I’m having a problem. I would like to load a file using Gdx.files.local. My understanding is that, when used on desktop, it uses the application’s root directory on Desktop. Would I be correct in assuming that the root directory in this scenario is this…?

PROJECT FOLDER (root directory)

  • bin
    • stuff inside
  • libs
    • stuff inside
  • src
    • stuff inside
  • res
    • t1.png

If I’m seeing this the right way, using Gdx.files.internal(“res/t1.png”) should be returning something other than a NullPointerException, yes? I saw some other thread where the suggested solution was to put files in the Android assets directory, which seems stupid because I don’t want to develop for Android. The strange thing is, while Gdx.files.internal doesn’t seem to find the file, java.io.File.exists(“res/t1.png”) does.

Could anybody shed some light on this situation? It’s annoying me quite a bit.
Thanks.

Those folders are not in the root folder, they are setup in the build path of your project and are wrapped with the .jar. Therefore they are internal files.

Just put things in the Assets folder of the android project, LibGDX is cross platform and all the folders are linked. Anything in the assets folder gets copied over to an assets folder for whatever platform you are exporting to.

You would use gdx.file.local when you want to receive files in the directory the jar is present like you said, say your game has an installer and everything is outside the jar, you would use this.

Please don’t call these methods stupid because you don’t understand it, if you don’t like it use your own API.

EDIT: Gdx.files.internal will only find files that are linked as a source folder, i.e the Assets folder.

Oh, please don’t take it the wrong way. I guess my choice of words wasn’t the best. I guess with just my lack of understanding of LibGDX, I got a little frustrated. Sorry about that. And thank you for your suggestion.

Gdx.files.local will find anything in the directory of the jar only, classpath is INSIDE the jar only. Internal turns into classpath if the file is not found, so it basically serves as both local and classpath combined. So you guys are both wrong.

Yes, what you are doing originally works fine. NORMALLY.

As for Gibbo, read the documentation before spouting nonsense:

[quote]Local files are stored relative to the application’s root or working directory on desktops and relative to the internal (private) storage of the application on Android. Note that Local and internal are mostly the same on the desktop.
[/quote]
Except that internal turns to classpath if it can’t find the file locally.

As for how folders work, those ARE the root folders when running a project in eclipse, so if he is using eclipse, anything that is at the same level as his src and bin folders WOULD be considered root, this is because things are run as if they were a jar in the project folder.

Here is the entire wiki page on filehandling:


and here is the official documentation:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/files/FileHandle.html
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Files.FileType.html#Internal