Multiple classes

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


[java]public class Main extends SimpleApplication{

public static void main(String[] args) {

Main app = new Main();

//remove initial screen


AppSettings settings = new AppSettings(true);

settings.put(“Width”, 800);

settings.put(“Height”, 600);

settings.put(“Title”, “”);

settings.put(“VSync”, true);

settings.put(“Samples”, 4);





public void simpleInitApp() {


//wereld inladen

Box b = new Box(Vector3f.ZERO, 100, 10, 100);

Geometry geom = new Geometry(“Box”, b);


//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);




//licht plaatsen

DirectionalLight dl = new DirectionalLight();

dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());


//inladen van player

Player pl = new Player(); //zo gaat het wel, alleen het manneke is ni te zien :confused:

//pl.initPlayer(); //da gaat ni, nullpointer… wss doek iet verkeerd aja :confused:





public void simpleUpdate(float tpf) {



public void simpleRender(RenderManager rm) {

//TODO: add render code




[java]public class Player extends Main implements AnimEventListener {

private AnimChannel channel;

private AnimControl control;

Node player;

public Player() {




// Nullpointer dus hier… van die pl.initPlayer(); in main

private void initPlayer(){

player = (Node) assetManager.loadModel(“Models/CBoy/cubeboyMesh.mesh.xml”);



control = player.getControl(AnimControl.class);


channel = control.createChannel();



public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

if (animName.equals(“Walkcycle”)) {

channel.setAnim(“Stand”, 0.50f);





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);




if (name.equals(“Wave”) && !keyPressed){

if (!channel.getAnimationName().equals(“Wave”)){

channel.setAnim(“Wave”, 0.50f);








SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
at mygame.Player.initKeys(
at mygame.Player.(
at mygame.Main.simpleInitApp(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(

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

You extend the main class and have an inputManager variable because of that but since you instantiate it as your own object and you dont actually start an application the inputManager is null. Dont extend main but pass a variable pointing to the application in the constructor of your class and then use that like aplication.getInputManager().

ik denk dat het het beste is om als het kan, te proberen 1 klasse te gebruiken. als dit niet kan, of het is veel gemakkelijker in meerdere klassen, hang ik alles aan de rootNode in de Main class. daar plaats ik dan ook de code om andere klassen te updaten. Het is ook meestal het beste om alle controls in de main klasse te regelen.

i think it’s the best to ,where possible, to use only one class. and when i have to use an other class, i always attach them too the rootNode and update them in the main class. it’s also easyest to react to input in the main class.

Thx guys! I’ll try what you said. sadly enough there will be added a lot more, so classes are needed :frowning: aren’t there any examples with classes? I already searched here and googled it, but didn’t find any, but i also can’t believe there aren’t examples with classes :s

Using classes like this is without question the way to go. All the examples won’t do this just to keep things as simple as possible and remain focussed on what they’re trying to teach you, the 3d engine itself, without over-complicating things.

  • Andy.