[英]Java LibGDX Texture gives null pointer exception
我一直在為一個項目使用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
代碼是:
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
的create
方法中(或之后,如果需要,可以是ApplicationAdapter
或Game
)。
另請參閱: https : //github.com/libgdx/libgdx/wiki/The-life-cycle
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.