[英]Java LibGDX Texture gives null pointer exception
I've been using LibGDX for a project and whenever i declare a Texture it gives : 我一直在为一个项目使用LibGDX,每当我声明一个Texture就会给出:
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
The code is : 代码是:
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");
}
} }
I am really stuck here . 我真的被困在这里。 Thanks in advance
提前致谢
You cant use (the majority of) libGDX before it is initialized. 在初始化之前,您不能使用(大多数)libGDX。 This is in or after the
create
method of your ApplicationListener
(or ApplicationAdapter
or Game
if your prefer). 这是在
ApplicationListener
的create
方法中(或之后,如果需要,可以是ApplicationAdapter
或Game
)。
See also: https://github.com/libgdx/libgdx/wiki/The-life-cycle 另请参阅: https : //github.com/libgdx/libgdx/wiki/The-life-cycle
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.