Hi, i followed the tutorials for beginners and after the “Hello animation” tutorial I tried to put it in different classes. But I always get a nullpointerexeption. Below are my classes and error
Main:
[java]public class Main extends SimpleApplication{
public static void main(String[] args) {
Main app = new Main();
//remove initial screen
app.setShowSettings(false);
AppSettings settings = new AppSettings(true);
settings.put(“Width”, 800);
settings.put(“Height”, 600);
settings.put(“Title”, “”);
settings.put(“VSync”, true);
settings.put(“Samples”, 4);
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
/*
//wereld inladen
Box b = new Box(Vector3f.ZERO, 100, 10, 100);
Geometry geom = new Geometry(“Box”, b);
geom.updateModelBound();
//plaatsen van texture op wereld
Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
Texture tex_gr = assetManager.loadTexture(“Textures/grass_1.jpg”);
mat.setTexture(“m_ColorMap”, tex_gr);
geom.setMaterial(mat);
*/
viewPort.setBackgroundColor(ColorRGBA.LightGray);
//licht plaatsen
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
//inladen van player
Player pl = new Player(); //zo gaat het wel, alleen het manneke is ni te zien
//pl.initPlayer(); //da gaat ni, nullpointer… wss doek iet verkeerd aja
//rootNode.attachChild(geom);
rootNode.setCullHint(CullHint.Never);
}
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}[/java]
Player:
[java]public class Player extends Main implements AnimEventListener {
private AnimChannel channel;
private AnimControl control;
Node player;
public Player() {
initKeys();
initPlayer();
}
// Nullpointer dus hier… van die pl.initPlayer(); in main
private void initPlayer(){
player = (Node) assetManager.loadModel(“Models/CBoy/cubeboyMesh.mesh.xml”);
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“Stand”);
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
if (animName.equals(“Walkcycle”)) {
channel.setAnim(“Stand”, 0.50f);
channel.setLoopMode(LoopMode.DontLoop);
channel.setSpeed(1f);
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
throw new UnsupportedOperationException(“Not supported yet.”);
}
private void initKeys() {
inputManager.addMapping(“Walkcycle”, new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping(“Wave”, new KeyTrigger(KeyInput.KEY_W));
inputManager.addListener(actionListener, “Walkcycle”);
inputManager.addListener(actionListener, “Wave”);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“Walkcycle”) && !keyPressed) {
if (!channel.getAnimationName().equals(“Walkcycle”)) {
channel.setAnim(“Walkcycle”, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
if (name.equals(“Wave”) && !keyPressed){
if (!channel.getAnimationName().equals(“Wave”)){
channel.setAnim(“Wave”, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
}[/java]
error:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Player.initKeys(Player.java:58)
at mygame.Player.(Player.java:28)
at mygame.Main.simpleInitApp(Main.java:55)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:186)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:134)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:183)
at java.lang.Thread.run(Thread.java:662)
the model is one that I made in blender, i tested it in the main class and it works fine..
someone can help me?
thx in advance