我已经创建了一个PythonInterpreter对象,并希望调用Java的功能,但不断收到错误:如何从嵌入Jython中调用java函数?
Exception in thread "main" Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'jytest2' is not defined
Java Result: 1
你如何称呼从实时运行系统的Java函数?
public static void main(String args[])
{
ModRet modRet = new ModRet();
jytest();
}
public void jytest()
{
PythonInterpreter interp = new PythonInterpreter();
interp.exec("print \'Hello; jython has successfully been embedded!\'");
interp.exec("print " + FPS);
interp.exec("jytest2()");
}
public void jytest2()
{
System.out.println("HIHIHI");
}
这将会是真正有用的,如果你能发布一些相关的Jython代码 – 2011-05-12 20:13:07
我确实发现做到这一点的一种方法:通过运行Jython的构造。但还有另一种方式吗? – orkel 2011-05-12 20:17:59
'interp.exec(String)'只能在Python/Jython语言中解释;你有没有为解释而创建的Python函数'jytest2()'?这是我从错误信息中可以理解的,因为它找不到函数...您可能需要先从具有该函数的库中导入,然后才能使用它。 – eee 2011-05-13 01:28:18