This article is a mirror article of machine translation, please click here to jump to the original article.

View: 31344|Reply: 0

[Source] class xx cannot access a member of class xx with modifiers "private"

[Copy link]
Posted on 5/28/2021 1:45:40 PM | | | |
Java reflection gets the field value, and the error is as follows:



Exception in thread "main" java.lang.IllegalAccessException: class demo. Test1 cannot access a member of class demo. Test1$User with modifiers "private"
        at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:385)
        at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:693)
        at java.base/java.lang.reflect.Field.checkAccess(Field.java:1096)
        at java.base/java.lang.reflect.Field.get(Field.java:417)
        at demo. Test1.main(Test1.java:13)
solution

When reflecting a private member variable of an operation class, you need to set the field to be accessible via field.setAccessible(true).



Code:








Previous:Difference between CrudRepository and JpaRepository in Spring Data JPA
Next:JPA Hibernate query result offset is not supported
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com