IllegalAccessException on public method

Discussion in 'Java' started by mike, Jul 10, 2004.

  1. mike

    mike Guest

    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
    mike, Jul 10, 2004
    #1
    1. Advertising

  2. On 10 Jul 2004 12:29:14 -0700, mike wrote:

    > 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.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Jul 10, 2004
    #2
    1. Advertising

  3. mike

    Liz Guest

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


    "mike" <> wrote in message
    news:...
    > 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
    Liz, Jul 10, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,340
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    546
    SpamProof
    Oct 21, 2003
  3. Ranger
    Replies:
    1
    Views:
    493
    John C. Bollinger
    Aug 4, 2003
  4. mike
    Replies:
    4
    Views:
    13,785
  5. Andreas Solsbach

    Classloader IllegalAccessException

    Andreas Solsbach, Oct 7, 2004, in forum: Java
    Replies:
    0
    Views:
    426
    Andreas Solsbach
    Oct 7, 2004
Loading...

Share This Page