Reputation: 101
I've been using LibGDX for a project and whenever i declare a Texture it gives :
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
Upvotes: 1
Views: 1532
Reputation: 8113
You cant use (the majority of) libGDX before it is initialized. This is in or after the create
method of your ApplicationListener
(or ApplicationAdapter
or Game
if your prefer).
See also: https://github.com/libgdx/libgdx/wiki/The-life-cycle
Upvotes: 4