Jython Question 
Author Message
 Jython Question

With Jython it is easy to access existing Java classes
- I tried the random number example at
http://www.*-*-*.com/

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!");
    }

Quote:
}

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.

Quote:
>>> 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



Mon, 21 Jun 2004 23:20:13 GMT  
 Jython Question
Making your World class public should help, i.e.

public class World { ...

Cheers,

ulbi

Quote:

> 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



Tue, 22 Jun 2004 00:30:32 GMT  
 Jython Question
Your class is not declared to be public.  This causes an
IllegalAccessException when Jython attempts to create a new instance.
Add the keyword 'public' before 'class World' and recompile.

http://java.sun.com/j2se/1.3/docs/api/java/lang/IllegalAccessExceptio...

brian

Quote:

> 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



Tue, 22 Jun 2004 04:35:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. A Jython question

2. Jython question concerning actionPerformed

3. Where to post Jython questions?

4. REPOST: Where to post Jython questions?

5. Two Jython Questions

6. jython question: accessing protected superclass methods

7. Jython questions

8. Jython question

9. Jython comments; Jython applets

10. Jython newbie question

11. jython beta question

12. Jython classpath question

 

 
Powered by phpBB® Forum Software