Hi everyone,
I'm making a 2d game and I've implemented collisions with box2d. Now, I get this error almost everytime I run my code, usually after a few seconds :
Could not invoke the "beginContact()" method for some reason. java.lang.reflect.InvocationTargetException 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:498) at shiffman.box2d.Box2DContactListener.beginContact(Box2DContactListener.java:54) at org.jbox2d.dynamics.contacts.Contact.update(Contact.java:330) at org.jbox2d.dynamics.ContactManager.collide(ContactManager.java:288) at org.jbox2d.dynamics.World.step(World.java:626) at shiffman.box2d.Box2DProcessing.step(Box2DProcessing.java:76) at shiffman.box2d.Box2DProcessing.step(Box2DProcessing.java:70) at Interface.draw(Interface.java:164) at processing.core.PApplet.handleDraw(PApplet.java:2437) at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1557) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316) Caused by: java.lang.NullPointerException at Interface.beginContact(Interface.java:403)
Everything that is within beginContact() stops being processed and I loose a big part of my game. I've read somewhere (https://stackoverflow.com/questions/24604289/collisions-in-processing-with-jbox2d-library) that it is a "spawning inside body" problem.
To be specific, my game generates asteroids randomly on the screen and they could be spawning inside each other. I would need a code to prevent that but not sure how it goes.
I have a MCVE ready if someone would like to see it.
Any insight on this error or help with code is appreciated.