Java LibGDX Texture提供空指针异常

时间:2015-12-23 22:33:24

标签: java android libgdx textures

我一直在使用LibGDX作为一个项目,每当我声明一个纹理它给出:

 Exception in thread "main" java.lang.NullPointerException
 at com.fistbump.patman.test.main(test.java:18)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140

代码是:

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;



public class test  {
public static void main(String[] args){
    Texture text = new Texture(Gdx.files.internal("Path.png"));
    OR
    Texture text = new Texture("Path.png");
}

}

我真的被困在这里了。提前致谢

1 个答案:

答案 0 :(得分:2)

在初始化之前,你无法使用(大多数)libGDX。这是在create的{​​{1}}方法中或之后(如果您愿意,可以是ApplicationListenerApplicationAdapter。)

另请参阅:https://github.com/libgdx/libgdx/wiki/The-life-cycle