From: Josh J. <jun...@gm...> - 2010-01-12 04:41:11
|
All you really need to ensure is that the Jython object that you wish to use from your java code is implementing a java interface. The factory should then be able to coerce the jython object. If you could send your factory code to the list then I'd be more than happy to take a look at it. On another note, you may be interested in taking a look at the PlyJy project which resides on Kenai. Jim Baker and myself have contributed a couple of different object factory implementations that you can use there. I also suggest taking a look at the online jython book located at jythonbook.com. We've written a chapter for that book which is all about using java and jython together. Hope this helps. As I had mentioned, please feel free to send your code and I'd gladly have a look. Best Josh Juneau Application Developer On Jan 11, 2010, at 5:30 PM, Sandra Johnson <san...@gm...> wrote: > Dear All, > > I am new to Jython and decided to try the code supplied in the > monthly Newsletters of September and October 2006 as I want to be > able to write some object factories for Python classes. > > I am coding and testing in Eclipse vsn 3.5.1 with PyDev plugin > installed, Jython 2.5.1 and JRE 6 > > I copied the code from the newsletters and changed the classes that > differed between the two newsletters to have either Sep or Oct in > them to distinguish where they came from. I have spent ages trying > to find the problem and getting nowhere. One suggestion in an > earlier post was to include into the python class > > import sys > sys.add_package(' java package' ) - so I added this code as well for > the java package 'jyinterface.interfaces' > > but to no avail, same NullPointerException & > ExceptionInInitializerError. > > The only differences between my code and the code provided by > Charlie Groves and Josh Juneau are java class name changes > (MainSep.java, MainOct.java in package jyinterface.interfaces, > EmployeeOct.py and EmployeeSep.py in the Jython project and I put > MainSep.java not in package jyinterface as Josh had, but in the > jyinterface.interfaces package). I also updated the references to > these classes. > > Here is the console output I get. Happy to supply the code if anyone > feels kind enough to have a look! > > Exception in thread "main" java.lang.ExceptionInInitializerError > at org.python.core.PyObject.<clinit>(PyObject.java:26) > at org.python.util.PythonInterpreter.<init> > (PythonInterpreter.java:72) > at org.python.util.PythonInterpreter.<init> > (PythonInterpreter.java:60) > at jyinterface.factory.EmployeeFactory.<init> > (EmployeeFactory.java:13) > at jyinterface.interfaces.MainOct.main(MainOct.java:18) > Caused by: java.lang.NullPointerException > at org.python.core.PyType.init(PyType.java:458) > at org.python.core.PyType.createType(PyType.java:1175) > at org.python.core.PyType.addFromClass(PyType.java:1116) > at org.python.core.PyType.fromClass(PyType.java:1182) > at org.python.core.PyType.<clinit>(PyType.java:30) > ... 5 more > > The lines that are being referred to in the error log are > > MainOct.java:18 > EmployeeFactory factory = new EmployeeFactory(); > EmployeeFactory.java:13 > PythonInterpreter interpreter = new PythonInterpreter(); > PythonInterpreter.java:60 > > public PythonInterpreter() { // line 59 > this(null, null); // line 60 > > PythonInterpreter.java:72 > dict = new PyStringMap(); > PyObject.java:26 > public static final PyType TYPE = PyType.fromClass > (PyObject.class); > > > PyType.java:458 > if (!Py.BOOTSTRAP_TYPES.contains(underlying_class)) { > PyType.java:1175 > newtype.init(c,needsInners); > PyType.java:1116 > return createType(c, needsInners); > PyType.java:1182 > addFromClass(PyType.class, null); > PyType.java:30 > public static PyType TYPE = fromClass(PyType.class); > > Cheers, > Sandra > --- > --- > --- > --------------------------------------------------------------------- > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast > and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |