I am dabbling with gw.lang.reflect.ReflectUtil from open source Gosu version 0.9-3 in an attempt to reflectively instantiate a Gosu class, and invoke a method on it. However, I’m getting the following error when I try to run it.
Exception in thread "main" java.lang.RuntimeException: Current module must not be null.
at gw.internal.gosu.parser.TypeLoaderAccess.returnFirstNonNullByName(TypeLoaderAccess.java:1152)
at gw.internal.gosu.parser.TypeLoaderAccess.getTypeByFullNameIfValid(TypeLoaderAccess.java:572)
at gw.internal.gosu.parser.TypeLoaderAccess.getTypeByFullNameIfValid(TypeLoaderAccess.java:539)
at gw.internal.gosu.parser.TypeLoaderAccess.getIntrinsicTypeByFullName(TypeLoaderAccess.java:519)
at gw.internal.gosu.parser.TypeSystemImpl.getByFullName(TypeSystemImpl.java:224)
at gw.lang.reflect.TypeSystem.getByFullName(TypeSystem.java:145)
at gw.lang.reflect.ReflectUtil.construct(ReflectUtil.java:19)
at gw.lang.reflect.ReflectUtil.constructGosuClassInstance(ReflectUtil.java:39)
at InvokeGosuHello.main(InvokeGosuHello.java:14)
Here’s a very simple test case:
Gosu side: (GosuHello.gs)
class GosuHello {
function helloWorld() {
print("Hello from Gosu!")
}
}
Java side: (InvokeGosuHello.java)
import gw.lang.reflect.ReflectUtil;
import gw.lang.reflect.gs.IGosuObject;
public class InvokeGosuHello {
public static void main(String[] args) {
IGosuObject gosuObj = ReflectUtil.constructGosuClassInstance("GosuHello");
ReflectUtil.invokeMethod(gosuObj, "helloWorld", null);
}
}
Any thoughts would be appreciated.
Thanks,
Jeff Klein
I think you're going to need to put that .gs file in a package and reference it with the whole path.
--
You received this message because you are subscribed to the Google Groups "gosu-lang" group.
To post to this group, send email to gosu...@googlegroups.com.
To unsubscribe from this group, send email to gosu-lang+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gosu-lang?hl=en.
--
-Alan
On Wed, Feb 15, 2012 at 12:31 PM, Vyktur with a Y
Thanks to everyone for your replies. I scoped my .gs file to a package (org.jeffklein.gosu), and added Gosu.init(). I am now able to instantiate the Gosu class, but I’m getting an NPE when it tries to invoke the method. Seems like I’m getting close!
Exception in thread "main" java.lang.NullPointerException
org.jeffklein.gosu.GosuHello@136a1a1
at gw.lang.reflect.ReflectUtil.extractRuntimeTypes(ReflectUtil.java:222)
at gw.lang.reflect.ReflectUtil.invokeMethod(ReflectUtil.java:107)
at org.jeffklein.gosu.InvokeGosuHello.main(InvokeGosuHello.java:13)
The java source now looks like:
package org.jeffklein.gosu;
import gw.lang.Gosu;
import gw.lang.reflect.ReflectUtil;
import gw.lang.reflect.gs.IGosuObject;
public class InvokeGosuHello {
public static void main(String[] args) {
Gosu.init();
IGosuObject gosuObj = ReflectUtil.constructGosuClassInstance("org.jeffklein.gosu.GosuHello");
System.out.println(gosuObj);
ReflectUtil.invokeMethod(gosuObj, "helloWorld", null);
Thank you for the pointer to the Goson project Brian. My project is indeed a maven project, and I am pulling in my Gosu dependencies from an internal repo (only because I didn’t know about the public repo @gosu-lang.org). I’ve changed my repository setting in my pom to match that in the Goson project pom:
<repositories>
<repository>
<id>gosu-lang.org-releases</id>
<name>Official Gosu website (releases)</name>
<url>http://gosu-lang.org/repositories/m2/releases</url>
</repository>
</repositories>
There are much more current versions of my gosu dependencies on the public site. Thank you again for the tip!!
Jeff
From: gosu...@googlegroups.com [mailto:gosu...@googlegroups.com] On Behalf Of Brian Chang
Sent: Wednesday, February 15, 2012 1:16 PM
To: gosu...@googlegroups.com
Thanks to everyone for your replies. I scoped my .gs file to a package (org.jeffklein.gosu), and added Gosu.init(). I am now able to instantiate the Gosu class, but I’m getting an NPE when it tries to invoke the method.
Exception in thread "main" java.lang.NullPointerException
org.jeffklein.gosu.GosuHello@136a1a1
at gw.lang.reflect.ReflectUtil.extractRuntimeTypes(ReflectUtil.java:222)
at gw.lang.reflect.ReflectUtil.invokeMethod(ReflectUtil.java:107)
at org.jeffklein.gosu.InvokeGosuHello.main(InvokeGosuHello.java:13)
The java source now looks like:
package org.jeffklein.gosu;
import gw.lang.Gosu;
import gw.lang.reflect.ReflectUtil;
import gw.lang.reflect.gs.IGosuObject;
public class InvokeGosuHello {
public static void main(String[] args) {
Gosu.init();
IGosuObject gosuObj = ReflectUtil.constructGosuClassInstance("org.jeffklein.gosu.GosuHello");
System.out.println(gosuObj);
ReflectUtil.invokeMethod(gosuObj, "helloWorld", null);
}
}
From: gosu...@googlegroups.com [mailto:gosu...@googlegroups.com] On Behalf Of Brian Chang
Sent: Wednesday, February 15, 2012 1:16 PM
To: gosu...@googlegroups.com
Subject: Re: [gosu-lang:718] Running a Gosu program from within Java
BTW, Jeff, since you're a Maven guy, I think you'll be delighted to learn that it's very convenient to do your stuff in a Maven-structured project and pull the Gosu dependencies. See https://github.com/gosu-lang/Goson for a barebones example.
Hi Carson,
I am developing in IntelliJ Ultimate. I haven’t installed the Gosu plugin yet for that reason. I have been meaning to install a community edition of IJ so that I can try it out, but alas I haven’t gotten around to it yet.
Just FYI, the NPE was my bad. I was using the 3-arg version of invokeMethod(), and passing a null list of method arguments. Changing to the 2-arg version took care of the problem, and I can invoke Gosu from Java- Very cool! Again, thanks to everyone for your replies.
Cheers,
Jeff