IllegalAccessException on public method

M

mike

Can some Java guru out there please explain this to me?

When using Method.invoke to call method m on an object of class Y, I
got an IllegalAccessException with the message 'Class X can not access
a member of class Y with modifiers "public"'

Class Y is a public class and its method m is a public method. I
verified the behavior with both Java 1.4.0 and Java 1.3.1. I thought
it was impossible to get an IllegalAccessException on a public method!

There's more: When I made the *constructor* of class Y public (it had
been package access), no exception was thrown and I was able to call
method m successfully using Method.invoke.

What sense does that make?

Thanks for any explanation you can give,
--Mike
 
A

Andrew Thompson

Can some Java guru out there please explain this to me?

When using Method.invoke to call method m

What method?
..on an object of class

What class?
...Y, I
got an IllegalAccessException with the message 'Class X can not access
a member of class Y with modifiers "public"'

Was it 'public static', or just 'public'?
There's more: When I made the *constructor* of class Y public (it had
been package access), no exception was thrown and I was able to call
method m successfully using Method.invoke.

That would seem to fit that the
method 'm' was not declared static.
 
L

Liz

Provide your actual code, with all the 'x', 'y', 'method', etc. who knows
what is going on.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top