我一直在为一个项目使用 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");
}
我真的被困在这里了。提前致谢
最佳答案
在初始化之前,您不能使用(大部分)libGDX。这是在 ApplicationListener
(或 ApplicationAdapter
或 Game
,如果您愿意)的 create
方法中或之后。
关于Java LibGDX Texture 给出空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34444752/