libgdx -- Gdx.files.internal(); --> File Not Found

19,025

Solution 1

Try "cleaning" your project by going to Project-> Clean. Also try "refreshing" your libGDX desktop folder by right clicking and using Gradle-> Refresh All

libGDX uses linked folders. You only need to copy the file to one of your asset folders (do this in eclipse, not in file explorer.)

Solution 2

What worked for me is, I had to go into assets->Build Path -> Configure Inclusion/Exclusion. I had to add all of my needed folders and files into the Inclusion section.

Solution 3

Answer is for outside of LibGDX, since someone already answered the original question. The answer may help with related efforts with files outside of LibGDX.

Assumption:

Packages exist ... Apple, Orange, Grape. Trying to use relative paths.

  1. Apple contains the file, Temp1.txt.
  2. Orange contains the file, Temp2.txt.
  3. Grape contains the file, Temp3.txt.

Access the files in the format, ...

  • "/Apple/Temp1.txt"
  • "/Orange/Temp2.txt"
  • "/Grape/Temp3.txt"
Share:
19,025

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I've been having trouble using the Gdx.files.internal() from libgdx; it seems that every time I run it as a desktop application i get this main error:

    Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: \data\sounds\music\mainmusic.mp3 (Internal) at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136) at com.badlogic.gdx.backends.lwjgl.audio.Mp3$Music.(Mp3.java:42) ... 10 more

    I've read 5 separate threads in the matter, one of which seemed like was the most likely problem so I've tried...

    1. creating a data folder under assets
    2. refreshing the eclipse explorer
    3. Project > clean
    4. manually creating an assets/data folder in bin (in core)
    5. triple checking file paths
    6. restarting the IDE

    my complete path is in /Flipcrew Legends-desktop/assets/data/sounds/music/mainmusic.mp3

    public class SplashScreen implements Screen{

    final FlipcrewLegends game;
    
    Texture splashTexture;
    Sprite splashSprite;
    SpriteBatch batch;
    TweenManager manager;
    Music introMusic;
    
    public SplashScreen(FlipcrewLegends game) {
        this.game = game;
    
        introMusic = Gdx.audio.newMusic(Gdx.files.internal("data/sounds/music/mainmusic.mp3"));
        introMusic.setLooping(true);
    
    }
    

    This However... seems to be working..

    @Override
    public void show() {
    
        splashTexture = new Texture("data/images/main/splash.png");
        splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    
        splashSprite = new Sprite(splashTexture);
        splashSprite.setColor(1, 1, 1, 0);
    }
    

    path: /Flipcrew Legends-desktop/assets/data/images/main/splash.png

    // Rest of class is omitted b/c it doesn't seem necessary (I can add it if requested)

    //unfortunately, Gdx.audio.newMusic doesnt seem to have a direct string path method so I couldn't try that out

    Additional Info: -> I've tried copying the assets folder in the desktop folder from core to no avail (deleted after) -> One thread said that libgdx usually takes the data from the android folder and then applies it to the desktop (unfortunately I started with only the desktop, no android) but I'm guessing libgdx has been nightly updated since the last date of that post, maybe an alternative has been added for that?

    edit:

    1. Just now after reverting assets/data/etc.... into assets/etc..... even the new Texture(path); is getting the same error - still doesn't work... retried methods above, will restart the computer after posting, might be a compiling issue.

    2. restarted computer, no difference

  • Tokenyet
    Tokenyet about 7 years
    I implemented i18n for my game, and could not load the certain file. This way seems strange but actually work lol.
  • comodoro
    comodoro over 5 years
    This is strange, but without the "/" at the beginning FileHandle.list() was including some files deleted ages ago, probably from some cache, and rebuilding the project or invalidating cache did not help - but only on some devices. Then again - adding the / probably just invalidated some other cache