"File not found" when running new LibGDX project

I trying to learn LibGDX, I install all the software listed here with a new Eclipse 4.3 on a fresh formatted mac OS X Maverick.

Everything goes smooth, after a reboot, I download, and execute the gdx-setup.jar, fill the form, and import into Eclipse.

No error, no warning, when I try to run the desktop. (Right click the desktop project, Run As -> Java Application).

I got this error

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: badlogic.jpg
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
at com.diesel.bugs.DieselBugs.create(DieselBugs.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)


Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: badlogic.jpg (Local)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:134)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)

I found a lot of similar issue here, I try them all without any good result... Last night I found this, very cool I have the latest Java 1.8, a mac, and Eclipse fit perfectly...

But no success, I try with Java 1.6 and 1.7, Always the same error (No file found, I kept Java 1.7)

I begin to do some debug, here my only modification of the original code generated by the importation.

package com.diesel.bugs;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class DieselBugs extends ApplicationAdapter {
    SpriteBatch batch;
    Texture imgExternal,imgLocal;

    @Override
    public void create () {
        batch = new SpriteBatch();
        String pathLocal = Gdx.files.getLocalStoragePath();
        String pathExternal = Gdx.files.getExternalStoragePath();
        Boolean isExternal = Gdx.files.isExternalStorageAvailable();
        Boolean isLocal = Gdx.files.isLocalStorageAvailable();
        imgExternal = new Texture(Gdx.files.external("/Desktop/badlogic.jpg"));
        imgLocal = new Texture(Gdx.files.local("badlogic.jpg")); 
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(imgExternal, 0, 0);
        batch.end();
    }
}

The weird thing is pathLocal is equal to "". Is it normal for Gdx.files.getLocalStoragePath() to return nothing (empty string)?

Also the

imgExternal = new Texture(Gdx.files.external("/Desktop/badlogic.jpg"));

Works great. only the local one gives the error, also isLocal, and isExternal return true.

And I try a lots of combinations, like /assets/data/badlogic.jpg, /assets/badlogic.jpg, /data/badlogic.jpg, data/badlogic.jpg, and badlogic.jpg.

The image badlogic.jpg is there and I put it in multiple places to be sure.

And now the reason why I'm here for help is I just try all the same step on a PC and everything works great.

What is wrong with my new mac and it's setting?


From libgdx wiki

When you run Desktop Project

The application will fail the first time. Open the Run Configuration you just created and set the working directory to the android/assets/ directory!

link your desktop project to android assets folder?

Go to Run => Run Configurations.. => choose DesktopLauncher, Arguments Tab => Working Directory => Others then browse to yourproject-android/assets/ and click Apply => Run

enter image description here


For those of us using Android Studio or IntelliJ IDEA, you need to follow these steps:

  1. Select Run -> Edit Configurations from the menu

  2. In the "Working Directory:" text box, append "/android/assets" to the path.

Note that if you execute tasks with gradle, this is not an issue. The gradle.build files are configured to use the assets folder from the android module.