Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

NullPointerException on calling Jython Class from Java application

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry,
Thanks for your help.
I am able to run the example with the changes you have done.
Raj
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic