9
votes

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

4

4 Answers

5
votes

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.)

2
votes

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.

1
votes

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"
0
votes

I had a same problem on Android Studio. I applied direct path for every each asset.

"C:\Users\Admin\Desktop\test1\android\assets/starfish.png"

enter public void create()
    {
        batch = new SpriteBatch();
        turtleTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/starfish.png") );
        turtleX = 20;
        turtleY = 20;
        turtleRectangle = new Rectangle( turtleX, turtleY,
                turtleTexture.getWidth(), turtleTexture.getHeight() );
        starfishTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/starfish.png") );
        starfishX = 380;
        starfishY = 380;
        starfishRectangle = new Rectangle( starfishX, starfishY,
                starfishTexture.getWidth(), starfishTexture.getHeight() );
        oceanTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/water.jpg") );
        winMessageTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/you-win.png") );
        win = false;
    }