3

I'm following the instruction in Jython and Java Integration.

The idea is simple; make Java interface, and matching python class. The issue is that with a interface function setX(), and setY(), I always get an error when I execute the file. I had to modify the name to such as setXvalue() or setYvalue() to avoid the error.

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class    
org.python.core.PyTraceback
at org.python.core.PyException.tracebackHere(PyException.java:158)

at org.python.core.PyObject._jcall(PyObject.java:3587)
at org.python.proxies.Arith$Arith$0.setX(Unknown Source) <-- ERROR???
at Main.main(Main.java:14)

package org.jython.book.interfaces;

This is a Java interface.

public interface ArithType {

    public void setX(int x); // <-- Error
    public void setYa(int x);
    public int getXa();
    public int getYa();
    public int add();
}

This is partial python class.

class Arith(ArithType):
    ''' Class to hold building objects '''

    def setX(self, x): # << Error
        self.x = x

You can find the source to test at this site - https://dl.dropboxusercontent.com/u/10773282/2013/Archive.zip

What's wrong with this? Why the method name setX() or setY() causes an error in execution?

1 Answer 1

1

Be careful with accessing attributes of an object in Jython; Jython uses implicit getters/setters, so reading from self.x invokes self.getX() and so on. Changing all occurrences of self.x to self._x (ditto for y) in your jython code made it work (for me). It is actually a convention in Python to name non-public members as _....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.