javaweb问题求解
package lab1_1;import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
import java.beans.VetoableChangeSupport;
import
public class limitstudent implements Serializable {
String name;
int age;
VetoableChangeSupport vcSupport;
String university;
public limitstudent() {
setName("tom");
setAge(21);
vcSupport=new VetoableChangeSupport(this);
setUniversity("GZU");
}
public void _tostring(){
System.out.println(" personal information:"+name+" "+age+" "+university);
}
public String getName() {
return name;
}
public void setName(String s) {
this.name = s;
}
public void setAge(int i) {
int old;
old= age;
try {
vcSupport.fireVetoableChange("age",old,i);
age=i;
} catch (PropertyVetoException e) {
System.out.println(e);
}
}
public int getAge() {
return age;
}
public String getUniversity() {
return university;
}
public void setUniversity(String s1) {
this.university = s1;
}
public void addVetoableChangeListener(VetoableChangeListener vc1){
vcSupport.addVetoableChangeListener(vc1);
}
public void removeVetoableChangeListener(VetoableChangeListener vc1){
vcSupport.removeVetoableChangeListener(vc1);
}
}
package lab1_1;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
public class testlimitstudent {
public testlimitstudent(){}
public static void main(String[] args) {
limitstudent st=new limitstudent();
System.out.println("初始信息:");
st._tostring();
st.addVetoableChangeListener(new VetoableChangeListener() {
@Override
public void vetoableChange(PropertyChangeEvent e)
throws PropertyVetoException {
if (Integer.parseInt((e.getNewValue()).toString())<=20)
throw(new PropertyVetoException("年龄太小"+e.getNewValue(),e));
}
});
st.setAge(19);
System.out.println("最后信息:");
st._tostring();
}
}
怎么破?
Exception in thread "Main Thread" java.lang.NullPointerException
at lab1_1.limitstudent.setAge(limitstudent.java:34)
at lab1_1.limitstudent.<init>(limitstudent.java:16)
at lab1_1.testlimitstudent.main(testlimitstudent.java:11)