• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

java.lang.IllegalAccessException When Using Reflection API

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got " java.lang.IllegalAccessException" when I use reflection API to access a private field. I have checked my policy file and it should be granted the permission needed. I am not sure what else have to be changed to allow the reflection API to access private members.

Here is my code:


And these 2 lines are included in my policy files "C:\Program Files\Java\jre6\lib\security\java.policy" and "C:\Program Files\Java\jdk1.6.0_17\jre\lib\security\java.policy"




Are these 2 lines enough to allow my reflection API to access private fields?
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to call setAccessible(true) on the methods. That is the method that will fail if the security manager disallows reading private members.
 
    Bookmark Topic Watch Topic
  • New Topic