From: Robert W. B. <rb...@di...> - 2001-10-17 02:33:19
|
Hello Hubert, On Tue, 16 Oct 2001, Hubert Yoshizaki wrote: > Hi, > I'm just experimenting with jythonc (new to Python/Jython and not reall= y experienced in Java > either for that matter) and came up with this problem. > > My python test code is simply this: > > import java > class tryJythonSample(java.lang.Object): > =A0=A0=A0=A0=A0=A0=A0 def __init__(self): > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "@sig public tryJython()" > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print "Constructor for tryJython" > =A0=A0=A0=A0=A0=A0=A0 def makeObject(self): > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "@sig public void makeObject()" > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print "I have just called a python me= thod!!" There is a class naming problem. The class statement defines "tryJythonSample", but the initializer tries to initialize the class "tryJython" in its @sig string. > after doing a jythonc tryJythonSample.py and get the corresponding clas= s files and java file > I created a java file that calls the methods. > My java file. > > import tryJythonSample.*; This import might be a problem. Unless you used the jythonc --package (-p) option to specify the tryJythonSample package, you should just use the following import: import tryJythonSample It's easy to forget Jython's 'extra' module layer (package/module/class a= s opposed to package/class). Using a jythonc-compiled class from Java acts as if there were no module. > import org.python.core.*; > > public class tryJythonMain > { > public static void main(String[] args) > { > tryJythonSample jySample =3D new tryJythonSample(); > jySample.makeObject(); > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 > } > }=A0=A0 =A0=A0=A0=A0 > > when I run my java file (tryJythonMain) I get the following: > > Exception in thread "main" java.lang.NullPointerException > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.PyJavaClass.lookup(PyJavaClass= .java:39) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.PyObject.<init>(PyObject.java:= 46) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.PySingleton.<init>(PySingleton= .java:8) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.PyNone.<init>(PyNone.java:7) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.PySystemState.initStaticFields= (PySystemState.java:341 > ) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.PySystemState.initialize(PySys= temState.java:320) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.Py.initProperties(Py.java:665) > =A0=A0=A0=A0=A0=A0=A0 at org.python.core.Py.initProxy(Py.java:709) > =A0=A0=A0=A0=A0=A0=A0 at tryJythonSample.<init>(tryJythonSample.java:10= 5) > =A0=A0=A0=A0=A0=A0=A0 at tryJythonMain.main(tryJythonMain.java:9) > > Can anyone tell me what I'm doing wrong? see notes in code samples. > Is there a problem with dependencies? no. -robert |