package com.itheima;
import java.beans.*;
public class Test7 {
//思路:通过Introspector类获得Bean对象的 BeanInfo,然后通过 BeanInfo来获取属性的描述器PropertyDescriptor,
//通过这个属性描述器就可以获取某个属性对应的 getter/setter方法,然后通过反射机制来调用这些方法。
public static void main(String[] args) throws Exception {
Class<?> clazz = Class.forName("com.itheima.Test7.JavaBean");
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
System.out.println(beanInfo); //这里无法输出,因为报错。错误描述为:
}
class JavaBean {
private boolean b;
private Integer i;
private String s;
private double d;
public boolean isB() {return b;}
public void setB(boolean b) {this.b = b;}
public Integer getI() {return i;}
public void setI(Integer i) {this.i = i;}
public String getS() {return s;}
public void setS(String s) {this.s = s;}
public double getD() {return d;}
public void setD(double d) {this.d = d;}
}
}
编译通过,运行报错,描述为:
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at com.itheima.Test7.main(Test7.java:29)
---------------------------------------------------------------------
请教各位,问题出在哪里了?
|
|