Jython Question

Andreas Ulbrich andreas.ulbrich at gmx.net
Thu Jan 3 11:30:32 EST 2002


Making your World class public should help, i.e.

public class World { ...

Cheers,

ulbi

Jesper Olsen wrote:

> With Jython it is easy to access existing Java classes
> - I tried the random number example at
> http://www.jython.org/docs/usejava.html´.
> 
> But I failed to create an example myself. Is it only packages that
> can be imported?
> 
> This is a java class that I would like to access 
> 
> class World {
>     public World() {
>         System.out.println("constructing World!");
>     }
> 
>     public void hi() {
>         System.out.println("Hi World!");
>     }
> }
> 
> 
> from jython - however I get an exception when try to instantiate this
> class
> in jython. Can anyone point out what is wrong in this example?
> 
> prompt% jython
> Jython 2.1 on java1.3.1 (JIT: null)
> Type "copyright", "credits" or "license" for more information.
> 
>>>>import World
>>>>w=World()
>>>>
> Traceback (innermost last):
>   File "<console>", line 1, in ?
> java.lang.IllegalAccessException
>         at java.lang.reflect.Constructor.newInstance(Native Method)
>         at org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:126)
>         at org.python.core.PyJavaInstance.__init__(PyJavaInstance.java:75)
>         at org.python.core.PyJavaClass.__call__(PyJavaClass.java:846)
>         at org.python.core.PyObject.__call__(PyObject.java:258)
>         at org.python.pycode._pyx2.f$0(<console>:1)
>         at org.python.pycode._pyx2.call_function(<console>)
>         at org.python.core.PyTableCode.call(PyTableCode.java:208)
>         at org.python.core.PyCode.call(PyCode.java:14)
>         at org.python.core.Py.runCode(Py.java:1135)
>         at org.python.core.Py.exec(Py.java:1157)
>         at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:148)
>         at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
>         at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
>         at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:44)
>         at org.python.util.InteractiveConsole.push(InteractiveConsole.java:83)
>         at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:62)
>         at org.python.util.jython.main(jython.java:199)
> 
> java.lang.IllegalAccessException: java.lang.IllegalAccessException
> 





More information about the Python-list mailing list