From: Erlend V <eb...@im...> - 2001-01-16 16:30:47
|
hi, I'm having some problems with the following situation: I have a Java class that I extend in Jython. When I try to use this Jython class from Java, I get an exception similar to the following: "TypeError: instance already instantiated for problem.JavaClass" What am I doing wrong? Erlend ----- Here is the console output and test programs: [evb@evb unittest]$ jythonc -p problem problem/PyClass.py .... stuff deleted...... [evb@evb unittest]$ java problem.UsesPyClass JavaClass called with 'hi from Java' Exception in thread "main" Java Traceback: at java.lang.Throwable.<init>(Throwable.java:84) at java.lang.Exception.<init>(Exception.java:35) at java.lang.RuntimeException.<init>(RuntimeException.java:39) at org.python.core.PyException.<init>(PyException.java:44) at org.python.core.PyException.<init>(PyException.java:56) at org.python.core.Py.TypeError(Py.java:120) at org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:88) at org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:72) at org.python.core.PyInstance.__init__(PyInstance.java:167) at org.python.core.Py.initProxy(Py.java:746) at problem.PyClass.<init>(PyClass.java:100) at problem.UsesPyClass.main(UsesPyClass.java:6) Traceback (innermost last): (no code object) at line 0 TypeError: instance already instantiated for problem.JavaClass The Java class that the jython class extends: ------ package problem; public class JavaClass{ public JavaClass(String name) { System.out.println("JavaClass called with '" + name + "'"); } } ----- The Jython class that extends this java class: ----- import problem class PyClass(problem.JavaClass): def myMethod(self): "@sig void myMethod()" print "python method myMethod called" if __name__ == "__main__": x = PyClass("hi from python") x.myMethod() ----- The Java class that uses the PyClass : ----- package problem; public class UsesPyClass { public static void main(String[] args) { PyClass py = new PyClass("hi from Java"); py.myMethod(); } } |