幕布斯1005
2018-12-17 15:15
报错内容:
D:\eclipse\workspace\Proxy/bin/com/sxw/simulationJdkProxy/$Proxy0.java
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sxw.simulationJdkProxy.Proxy.newProxyInstance(Proxy.java:77)
at com.sxw.simulationJdkProxy.Test.main(Test.java:7)
Exception in thread "main" java.lang.NullPointerException
at com.sxw.simulationJdkProxy.Test.main(Test.java:8)
代码部分:
//编译部分
//编译器
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
//获取文件管理器
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
//获取文件
Iterable fileMag=fileManager.getJavaFileObjects(fileName);
//编译任务
CompilationTask task=compiler.getTask(null, fileManager, null, null, null, fileMag);
//进行编译
task.call();
fileManager.close();
//load到内存中
ClassLoader cl = ClassLoader.getSystemClassLoader();
Class class1 = cl.loadClass("com.sxw.simulationJdkProxy.$Proxy0");
//得到构造器,根据构造器创建对象
Constructor constructor =class1.getConstructor(interf);
return constructor.newInstance(new Car());
D:\eclipse\workspace\Proxy/bin/com/sxw/simulationJdkProxy/$Proxy0.java
这个目录我感觉不大对
模式的秘密---代理模式
54914 学习 · 98 问题
相似问题