Reputation: 317
Cannot load any texture, it worked fine, now it doesn't work, don't know why.
import com.badlogic.gdx.graphics.Texture;
public class MiJuego implements ApplicationListener {
public Texture textura = new Texture(Gdx.files.internal("prueba.png"));
@Override
public void create() {
// TODO Auto-generated method stub
}
Exception in thread "main" java.lang.NullPointerException at com.alex.version1.MiJuego.(MiJuego.java:16) at com.alex.version1.Main.main(Main.java:14)
Line 16 is exactly the one in which I create the texture. I have tested it in several projects but it doesn't work. The images are set in the asset folder in my android project.
Upvotes: 3
Views: 293
Reputation: 10320
Try it like this:
public class MiJuego implements ApplicationListener {
public Texture textura;
@Override
public void create() {
textura = new Texture(Gdx.files.internal("prueba.png"))
...
}
You were creating the Texture at the load time of the ApplicationListener, not create time. Libgdx isn't initialized then. So any Gdx.xxx call will throw a NullPointerException.
Upvotes: 5