IllegalAccessException on public method

M

mike

When calling Method.invoke, I get
'Class X can not access a member of class Y with modifiers "public"'
The method I am trying to invoke is in class Y, and is a public
method. I thought it was impossible to get an IllegalAccessException
on a public member. Can anyone clarify this for me?
Thanks,
 
X

xarax

mike said:
When calling Method.invoke, I get
'Class X can not access a member of class Y with modifiers "public"'
The method I am trying to invoke is in class Y, and is a public
method. I thought it was impossible to get an IllegalAccessException
on a public member. Can anyone clarify this for me?
Thanks,

Please post a compilable example and we'll take a
look at it. We also need to know the JDK level (is
it J2SE 1.3 or 1.4?, etc.).
 
M

mike

xarax said:
Please post a compilable example and we'll take a
look at it. We also need to know the JDK level (is
it J2SE 1.3 or 1.4?, etc.).

Thanks. I'll try to extract an example of reasonable size. Right
now, the failing code is embedded in several thousand lines of
application code and middleware, including a roll-your-own replacement
for Java RMI (all in Java) that we did back in 2000.

The Java version is 1.4.0-b92 (on Windows XP).
 
N

Neal Gafter

mike said:
When calling Method.invoke, I get
'Class X can not access a member of class Y with modifiers "public"'
The method I am trying to invoke is in class Y, and is a public
method. I thought it was impossible to get an IllegalAccessException
on a public member. Can anyone clarify this for me?

The class Y isn't public, or isn't accessible from X.
 
M

mike

Neal Gafter said:
The class Y isn't public, or isn't accessible from X.

Y is public, and both X and Y are loaded from the same ClassLoader in
the same JVM.

I FOUND A FIX, bit I don't understand it. I made Y's *constructor*
public, then the Method.invoke (on method m of Y) worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top