代码如下:- import java.io.*;
- import java.util.*;
- public class ReflectionTest
- {
- public static void main(String[] args) throws Exception
- {
- String name="cn.he.myreflect.MyText";
- Class classzz=Class.forName(name);
- classzz.newInstance();
- }
- }
- 错误提示:
- Exception in thread "main" java.lang.IllegalAccessException: Class ReflectionTes
- t can not access a member of class cn.he.myreflect.MyText with modifiers ""
- at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
- at java.lang.Class.newInstance0(Class.java:349)
- at java.lang.Class.newInstance(Class.java:308)
- at ReflectionTest.main(ReflectionTest.java:15)
复制代码 |