user2246120
user2246120

Reputation: 1505

Nullpointer exception when loading texture in libgdx

I get a nullpointer exception when loading splash.png. It works running on android, but throws an exception when running on the desktop even though the file is in android's asset folder and exists in the desktop's asset folder.

Any ideas what's happening? I did clean, restarted eclipse, re-imported the projects...

enter image description here

public class MainMenuScreen implements Screen {

@Override
public void show() {
    Texture background = new Texture(Gdx.files.internal("data/splash.png"));

    }

}

Upvotes: 0

Views: 1598

Answers (1)

Daahrien
Daahrien

Reputation: 10320

It should work like that, your assets folder is not correctly linked.

Taken from here: https://github.com/libgdx/libgdx/wiki/Manual-project-setup#asset-folder-setup

" -Click the Source tab, click Link Source, Browse, select the "assets" folder from your Android project and click OK.

-Specify "assets" for the folder name and click Finish then OK.

Note: If your desktop and Android projects are in the same parent folder, you can use "PARENT-1-PROJECT_LOC/gamename-android/assets" for the location of the linked assets folder, where "gamename-android" is the name of your Android project. This is better than a hard-coded path if you plan on sharing your projects with others."

Upvotes: 1

Related Questions