• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException on calling Jython Class from Java application

 
Raj Sikka
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am getting NullPointerException on calling Jython class from java code.
Following are the source code files:
.py file is :
import java
import sys
from math import *

class CalledByJava(java.lang.Object):
def __init__(self, equation):
"@sig public CalledByJava(String equation)"
self.equation = equation

def solve(self):
"@sig public float solve()"
result = eva(self.equation)
return float(result)


if __name__ == '__main__':
jt = CalledByJava(sys.argv[1])
print jt.solve()
.java file is :
public class CallJython {
public static void main(String[] args) {
System.out.println("Calling Jython function :"+args[0]);
CalledByJava cbj = new CalledByJava(args[0]);
System.out.println(cbj.solve());
}
}
Error i am getting is :
Exception in thread "main" java.lang.NullPointerException
at org.python.core.PyJavaClass.lookup(PyJavaClass.java:43)
at org.python.core.PyObject.<init>(PyObject.java:46)
at org.python.core.PySingleton.<init>(PySingleton.java:8)
at org.python.core.PyNone.<init>(PyNone.java:10)
at org.python.core.PySystemState.initStaticFields(PySystemState.java:396
)
at org.python.core.PySystemState.initialize(PySystemState.java:375)
at org.python.core.Py.initProperties(Py.java:696)
at org.python.core.Py.initProxy(Py.java:738)
at CalledByJava.__initProxy__(CalledByJava.java:135)
at CalledByJava.<init>(CalledByJava.java:113)
at CallJython.main(CallJython.java:4)
Please help me out.
Thanks,
Raj
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the following
But to get it I had to change your .py file to:

Notice the triple double-quotes (""") on the doc strings!
I also had to change eval to evaluate to get it into this post.
[ January 15, 2004: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On second thoughts, I cannot see why using triple double-quotes should make any difference. In "Python Essentials" only single double-quotes were used. In the Jython site's example triple double-quotes were used. I don't know, the problem you are experiencing must be due to something else...
Can you get the example given in the FAQ to work?
[ January 15, 2004: Message edited by: Barry Gaunt ]
 
Raj Sikka
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry,
Thanks for your help.
I am able to run the example with the changes you have done.
Raj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic