[Py4j-users] Calling python from java : py4j.Py4JException: An exception was raised by the Python P
Status: Beta
Brought to you by:
barthe
From: sudheera N. <sud...@gm...> - 2015-10-17 03:14:16
|
Hi I am trying to use py4j to call python method from java. I was successful in calling java methods from python. But I need to initiate the call from java side as java is my main program and I want to interface a power system simulation software called PowerFactory to java via python, (python provide nice interface to handle the PowerFactory ) . So, When I try to call the python from java I get following error. ERROR:py4j.java_gateway:Unknown command runPowerFactory Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python33\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "C:\Python33\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace) File "C:/Program Files (x86)/DIgSILENT/PowerFactory 15.1/python/PhdTheses_extClass.py", line 44, in <module> abc = toFromjava_ex.CollectDemandData(toFromjava1) File "C:\Python33\lib\site-packages\py4j\java_gateway.py", line 813, in __call__ answer, self.gateway_client, self.target_id, self.name) File "C:\Python33\lib\site-packages\py4j\protocol.py", line 308, in get_return_value format(target_id, ".", name), value) py4j.protocol.Py4JJavaError: An error occurred while calling o7.CollectDemandData. : py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: x at py4j.Protocol.getReturnValue(Protocol.java:434) at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:113) at com.sun.proxy.$Proxy0.runPowerFactory(Unknown Source) at repastextrun.JavaPyCall.CollectDemandData(JavaPyCall.java:10) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381) at py4j.Gateway.invoke(Gateway.java:259) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.GatewayConnection.run(GatewayConnection.java:209) at java.lang.Thread.run(Unknown Source) +++++++++++++++++++++++++++++++++++++++++++++++++++ My java Interface looks like package repastextrun; public interface javaPyCallInt { public void runPowerFactory(); } +++++++++++++++++++++++++++++++++++++++++++++++++ And the java class that I'm calling python looks like package repastextrun; import java.io.IOException; import py4j.GatewayServer; public class JavaPyCall { public void CollectDemandData(javaPyCallInt javaInt) throws IOException{ javaInt.runPowerFactory(); System.out.println(javaInt); } public static void main(String[] args) { GatewayServer server = new GatewayServer(new JavaPyCall()); server.start(); } } -- Sudheera Navaratne |