From: Hubert Y. <yos...@da...> - 2001-10-16 23:16:49
|
<html> Hi,<br> I'm just experimenting with jythonc (new to Python/Jython and not really experienced in Java either for that matter) and came up with this problem.<br> <br> My python test code is simply this:<br> <br> <font color="#0000FF"><i>import java<br> class tryJythonSample(java.lang.Object):<br> def __init__(self):<br> "@sig public tryJython()"<br> print "Constructor for tryJython"<br> def makeObject(self):<br> "@sig public void makeObject()"<br> print "I have just called a python method!!"<br> <br> </font></i><font color="#000000">after doing a jythonc tryJythonSample.py and get the corresponding class files and java file I created a java file that calls the methods.<br> My java file.<br> <br> </font><font color="#0000FF"><i>import tryJythonSample.*;<br> import org.python.core.*;<br> <br> public class tryJythonMain<br> {<br> public static void main(String[] args)<br> {<br> tryJythonSample jySample = new tryJythonSample();<br> jySample.makeObject();<br> <br> }<br> } </font></i><font color="#000000"> <br> <br> when I run my java file (tryJythonMain) I get the following:<br> <br> </font><font color="#0000FF"><i>Exception in thread "main" java.lang.NullPointerException<br> at org.python.core.PyJavaClass.lookup(PyJavaClass.java:39)<br> at org.python.core.PyObject.<init>(PyObject.java:46)<br> at org.python.core.PySingleton.<init>(PySingleton.java:8)<br> at org.python.core.PyNone.<init>(PyNone.java:7)<br> at org.python.core.PySystemState.initStaticFields(PySystemState.java:341<br> )<br> at org.python.core.PySystemState.initialize(PySystemState.java:320)<br> at org.python.core.Py.initProperties(Py.java:665)<br> at org.python.core.Py.initProxy(Py.java:709)<br> at tryJythonSample.<init>(tryJythonSample.java:105)<br> at tryJythonMain.main(tryJythonMain.java:9)<br> <br> </font></i><font color="#000000">Can anyone tell me what I'm doing wrong?<br> Is there a problem with dependencies?<br> Or is it something really dumb and simple that tells me I'm simply too tired to think properly? <br> Any help would be greatly appreciated.<br> Thanks,<br> Hubert</font> <BR> </html> |
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 |
From: Hubert Y. <yos...@da...> - 2001-10-17 16:23:37
|
<html> Hi Robert,<br> Thanks for the advice, <br> <br> >There is a class naming problem.=A0 The class statement defines<br> >"tryJythonSample", but the initializer tries to initialize the<br> >class "tryJython" in its @sig string.<br> <br> ahaha, don't know how I was blind/dumb enough to miss something as simple as that. Must have been half-asleep when I miss-typed that. Oh well. :P<br> <br> >> import tryJythonSample.*;<br> ><br> >This import might be a problem.=A0 Unless you used the jythonc --package<br> >(-p) option to specify the tryJythonSample package, you should just use<br> >the following import:<br> ><br> >import tryJythonSample<br> <br> still having problems...<br> <br> tried the 'import tryJythonSample' (without using the jythonc --package option)<br> <br> <font color=3D"#0000FF"><i>Exception in thread "main" java.lang.NullPointerException<br> at org.python.core.PyJavaClass.lookup(PyJavaClass.java:39)<br> at org.python.core.PyObject.<init>(PyObject.java:46)<br> at org.python.core.PySingleton.<init>(PySingleton.java:8)<br> at org.python.core.PyNone.<init>(PyNone.java:7)<br> at org.python.core.PySystemState.initStaticFields(PySystemState.java:341<br> )<br> at org.python.core.PySystemState.initialize(PySystemState.java:320)<br> at org.python.core.Py.initProperties(Py.java:665)<br> at org.python.core.Py.initProxy(Py.java:709)<br> at tryJythonSample.<init>(tryJythonSample.java:105)<br> at tryJythonMain.main(tryJythonMain.java:8)<br> <br> </font></i><font color=3D"#000000">tried the 'import tryJythonSample.* when using the jythonc --package option.<br> got the error<br> <br> </font><font color=3D"#0000FF"><i>C:\Hubert\Work\Projects\tryJython\tryJytho= nProject>java tryJythonMain<br> Exception in thread "main" java.lang.NullPointerException<br> at org.python.core.PyJavaClass.lookup(PyJavaClass.java:39)<br> at org.python.core.PyObject.<init>(PyObject.java:46)<br> at org.python.core.PySingleton.<init>(PySingleton.java:8)<br> at org.python.core.PyNone.<init>(PyNone.java:7)<br> at org.python.core.PySystemState.initStaticFields(PySystemState.java:341<br> )<br> at org.python.core.PySystemState.initialize(PySystemState.java:320)<br> at org.python.core.Py.initProperties(Py.java:665)<br> at org.python.core.Py.initProxy(Py.java:709)<br> at tryJythonSample.tryJythonSample.<init>(tryJythonSample.java:107)<br> at tryJythonMain.main(tryJythonMain.java:8)<br> <br> <br> </font></i><font color=3D"#000000">error wise, unless I'm mistaken, it seems to be running into the same problem each time <br> Any ideas?<br> <br> Hubert<br> <br> <br> (for others, here's the code...)<br> <br> import org.python.core.*;<br> import tryJythonSample;<br> <br> public class tryJythonMain<br> {<br> public static void main(String[] args)<br> {<br> tryJythonSample jySample =3D new tryJythonSample();<br> jySample.makeObject();<br> =20 &nbs= p; &n= bsp; = &nbs= p; &n= bsp; <br> }<br> }<br> <br> import java<br> class tryJythonSample(java.lang.Object):<br> def __init__(self):<br> "@sig public tryJythonSample()"<br> print "Constructor for tryJythonSample"<br> def makeObject(self):<br> "@sig public void makeObject()"<br> print "I have just called a python method!!"<br> <br> <br> <br> </font> <BR> </html> |
From: Robert W. B. <rb...@di...> - 2001-10-18 03:18:10
|
Hello Hubert, On Wed, 17 Oct 2001, Hubert Yoshizaki wrote: <snip> > still having problems... > > tried the 'import tryJythonSample'=A0 (without using the jythonc --pack= age > option) > > 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(PySystemState.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:8) > > tried the 'import tryJythonSample.* when using the jythonc --package > option. > got the error > > C:\Hubert\Work\Projects\tryJython\tryJythonProject>java tryJythonMain > 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(PySystemState.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.tryJythonSample.<init>(tryJythonSample.java:107) > =A0=A0=A0=A0=A0=A0=A0 at tryJythonMain.main(tryJythonMain.java:8) > > > error wise, unless I'm mistaken, it seems to be running into the same > problem each time > Any ideas? > > Hubert I'm not sure this helps, but the code you list below works fine for me (linux+sunJDK1.3). One thing that might be worth checking is whether the tryJythonSample class actually exists in a file called "tryJythonSample.py". The matching classname/filename is required here, and a difference in those names makes a NPE like you are seeing. If that's no help, check back again :) -robert > (for others, here's the code...) > > import org.python.core.*; > import tryJythonSample; > > 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 > } > } > > 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 tryJythonSample()" > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print "Constructor for tryJythonSampl= e" > =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!!" > > > _______________________________________________ Jython-users mailing li= st > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |