Hello,
I am getting a odd null pointer:
[java]at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:332)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1015)
at com.jme3.bullet.PhysicsSpace.addRigidBody(PhysicsSpace.java:550)
at com.jme3.bullet.PhysicsSpace.addCollisionObject(PhysicsSpace.java:391)
at com.jme3.bullet.control.RigidBodyControl.setPhysicsSpace(RigidBodyControl.java:241)
at com.jme3.bullet.PhysicsSpace.add(PhysicsSpace.java:373)
at lcs.electron.client.Communication.loadCell(Communication.java:301)
at lcs.electron.client.Window.updateCells(Window.java:251)
at lcs.electron.client.Window.updatePlayerPosition(Window.java:461)
at lcs.electron.client.Window.simpleUpdate(Window.java:224)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)[/java]
In this code:
[java]Spatial b = loadBlock(ids[count]);
RigidBodyControl rbc = new RigidBodyControl(0.0f);
DataHandler.physics.getPhysicsSpace().add(rbc);
b.addControl(rbc);
cell.attachChild(b);[/java]
I am not sure what I am doing wrong, but apparently something!
Any help would be great, Thanks
What is the nullpointer refering to?
Debug your code or do a System.out for every variable in that line to find out what is null.
Does [java]DataHandler.physics.getPhysicsSpace()[/java] return null?
I am unable to find what is null. Using a debugger every one of my variables look like they are good.
The problem occurs when this gets run, but neither the RigidBodyControl (rbc) nor the BulletAppState (DataHandler.physics) is null…
[java]
300: RigidBodyControl rbc = new RigidBodyControl(0.0f);
301: DataHandler.physics.getPhysicsSpace().add(rbc);
[/java]
[java]
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:332)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1015)
at com.jme3.bullet.PhysicsSpace.addRigidBody(PhysicsSpace.java:550)
at com.jme3.bullet.PhysicsSpace.addCollisionObject(PhysicsSpace.java:391)
at com.jme3.bullet.control.RigidBodyControl.setPhysicsSpace(RigidBodyControl.java:241)
at com.jme3.bullet.PhysicsSpace.add(PhysicsSpace.java:373)
at lcs.electron.client.Communication.loadCell(Communication.java:301)
at lcs.electron.client.Window.updateCells(Window.java:251)
at lcs.electron.client.Window.updatePlayerPosition(Window.java:461)
at lcs.electron.client.Window.simpleUpdate(Window.java:224)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)
[/java]
Sadly, I am still getting the same error… I now have:
[java]Spatial b = loadBlock(ids[count]);
RigidBodyControl rbc = new RigidBodyControl(0.0f);
b.addControl(rbc);
DataHandler.physics.getPhysicsSpace().add(rbc);
cell.attachChild(b);[/java]
[java]
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:332)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1015)
at com.jme3.bullet.PhysicsSpace.addRigidBody(PhysicsSpace.java:550)
at com.jme3.bullet.PhysicsSpace.addCollisionObject(PhysicsSpace.java:391)
at com.jme3.bullet.control.RigidBodyControl.setPhysicsSpace(RigidBodyControl.java:241)
at com.jme3.bullet.PhysicsSpace.add(PhysicsSpace.java:373)
at lcs.electron.client.Communication.loadCell(Communication.java:359)
at lcs.electron.client.Window.updateCells(Window.java:251)
at lcs.electron.client.Window.updatePlayerPosition(Window.java:461)
at lcs.electron.client.Window.simpleUpdate(Window.java:224)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)[/java]
OK, fixed the Node throwing the Null (Don’t know what I did, it just started working as I added other nodes), but now it is bouncing…
My player object is bouncing up and down on the ground and I am not sure why. I have not told it to (I don’t think)…
I optimized the code just a touch, still don’t know what is wrong. I am unable to change the height or speed of the bounce but adjusting the arguments of the BetterCharacterControl.
[java]DataHandler.players.attachChild(new Node(DataHandler.playersData.get(playerIndex).id + “”));
DataHandler.player.playerNode = (Node) DataHandler.players.getChild(“Player”);
Spatial player = assetManager.loadModel(“Models/basic_man/basic_man.j3o”);
DataHandler.player.playerPhysics = new BetterCharacterControl(0.5f, 1.5f, 10f);
DataHandler.player.playerPhysics.setGravity(new Vector3f(0f, -9.81f, 0f));
DataHandler.player.playerPhysics.setJumpForce(new Vector3f(0f, 100f, 0f));
DataHandler.player.playerNode.addControl(DataHandler.player.playerPhysics);
DataHandler.physics.getPhysicsSpace().add(DataHandler.player.playerPhysics);
Material playerMat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
playerMat.setBoolean(“UseMaterialColors”, true);
ColorRGBA c = ColorRGBA.randomColor();
playerMat.setColor(“Ambient”, c);
playerMat.setColor(“Diffuse”, c);
player.setMaterial(playerMat);
DataHandler.player.playerNode.attachChild(player);[/java]