Hey all,
Have been working with several Java Game books and coding basic stuff in Groovy. I've learned alot about converting and working with Java code and converting minor things to get it to work with Groovy. Usuallt the vast majority of the code is the same but there are only minor changes that need to be made to get things to work in Groovy.
I recently decided to work with Jmonkey and have been going through the tutorials without too many issues and converting things over fairly easily but ran into a stumbling block.
The HelloIntersection Tutorial references something called cam.getLocation() at line 160. In looking at other code, I can see this as part of com.jme.renderer. But when I try to run the code, I'm always getting an error like the following when firing a bullet:
java.lang.NullPointerException
at HelloIntersection$FireBullet.propertyMissing(HelloIntersection.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
at groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:754)
at groovy.lang.MetaClassImpl$11.getProperty(MetaClassImpl.java:1775)
at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:69)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:241)
at HelloIntersection$FireBullet.performAction(HelloIntersection.groovy:160)
at com.jme.input.ActionTrigger.performAction(ActionTrigger.java:264)
at com.jme.input.ActionTrigger$CommandTrigger.performAction(ActionTrigger.java:291)
at com.jme.input.InputHandler.processTriggers(InputHandler.java:425)
at com.jme.input.InputHandler.update(InputHandler.java:410)
at com.jme.app.BaseSimpleGame.updateInput(BaseSimpleGame.java:327)
at com.jme.app.BaseSimpleGame.update(BaseSimpleGame.java:219)
at com.jme.app.SimpleGame.update(SimpleGame.java:56)
at com.jme.app.BaseGame.start(BaseGame.java:84)
at com.jme.app.BaseGame$start.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at HelloIntersection.main(HelloIntersection.groovy:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1305)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:717)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:270)
at groovy.lang.GroovyShell.run(GroovyShell.java:226)
at groovy.lang.GroovyShell.run(GroovyShell.java:156)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494)
at groovy.ui.GroovyMain.run(GroovyMain.java:309)
at groovy.ui.GroovyMain.process(GroovyMain.java:295)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112)
at groovy.ui.GroovyMain.main(GroovyMain.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
For all intents and purposes, none of the code changed, only small cleanups are done (like making sure variables are properly declared so Groovy doesn't try to do it dynamically).
Does anyone know what would be causing this issue? Line 160 appears to be...
bullet.setLocalTranslation(new Vector3f(cam.getLocation()));