[SOLVED] NullPointerException: the native object does not exist

that’s the error name and it comes on this code:

   ballphy = new RigidBodyControl(5f); //(ballphy is created)
   ballphy.setCcdSweptSphereRadius(1f);  //(here cones the error)
   state.getPhysicsSpace().add(allphy);  //(state is of BulletAppState)
1 Like

You haven’t set a collisionshape.

The method setCcdSweptSphereRadius bubbles up to a RigidBody object called rBody which is only created when you set a collision shape.

Take a look at the static method CollisionShapeFactory.createDynamicMeshShape(Spatial spatial).


Thanks i will try it

Is the trouble solved?




i belive your ballMesh is not Sphere object mesh. As you can see below you can also use: SphereCollisionShape

Because if it is sphere class object then

ballphy = new RigidBodyControl(5f);

should auto choose proper CollisionShapeFactory.

Here is how it choose based on what Spatial is:

(jmonkeyengine/RigidBodyControl.java at master · jMonkeyEngine/jmonkeyengine · GitHub)

 * Set the collision shape based on the controlled spatial and its
 * descendents.
protected void createCollisionShape() {
    if (spatial == null) {
    if (spatial instanceof Geometry) {
        Geometry geom = (Geometry) spatial;
        Mesh mesh = geom.getMesh();
        if (mesh instanceof Sphere) {
            collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
        } else if (mesh instanceof Box) {
            collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
    if (mass > 0) {
        collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
    } else {
        collisionShape = CollisionShapeFactory.createMeshShape(spatial);

its correct what you do, i just want mention that your situation is probably different because Mesh is not Sphere object so it cant determine how to generate it.

also it would be better if you provide this in constructor so this do not calculate it earlier itself.

ballMesh is Sphere.

I hope that I understood properly:


But this way I like more:



it will work too. :slight_smile: myself i use this way. But looks like you are missing “mass” param.
Dynamic objects need mass.

RigidBodyControl bullet = new RigidBodyControl(new SphereCollisionShape(0.1f), 0.0001f);

but if your ballMesh is Sphere, then this should just work without manually create collisionmesh.


RigidBodyControl bullet = new RigidBodyControl(0.0001f);

should just work for Sphere mesh, see wiki below example:


this should just work like is here. if not then wiki need updates or there is some bug.

In this code occurs exception:

вер. 06, 2019 1:11:55 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.NullPointerException: The native object does not exist.
at com.jme3.bullet.objects.PhysicsRigidBody.setCcdSweptSphereRadius(Native Method)
at com.jme3.bullet.objects.PhysicsRigidBody.setCcdSweptSphereRadius(PhysicsRigidBody.java:380)
at mygame.Main.shootCannonBall(Main.java:149)
at mygame.Main$1.onAction(Main.java:160)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:446)
at com.jme3.input.InputManager.processQueue(InputManager.java:864)
at com.jme3.input.InputManager.update(InputManager.java:914)
at com.jme3.app.LegacyApplication.update(LegacyApplication.java:724)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:227)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:748)

You need to add a collision shape.



just after new RigidBody, so CCD methods will be after, i think this will fix.

@jayfella collision shape should auto-add on spatial assign. (control assign)

Thanks guys

this works now, when you moved it, right?

Yes, now works fine