您的位置:首页 > 编程语言 > Java开发

javaweb问题求解

2014-04-02 19:15 288 查看
packagelab1_1;

importjava.beans.PropertyVetoException;

importjava.beans.VetoableChangeListener;

importjava.beans.VetoableChangeSupport;

importjava.io.Serializable;

publicclasslimitstudentimplementsSerializable{

Stringname;

intage;

VetoableChangeSupportvcSupport;

Stringuniversity;

publiclimitstudent(){

setName("tom");

setAge(21);

vcSupport=newVetoableChangeSupport(this);

setUniversity("GZU");

}

publicvoid_tostring(){

System.out.println("personalinformation:"+name+""+age+""+university);

}

publicStringgetName(){

returnname;

}

publicvoidsetName(Strings){

this.name=s;

}

publicvoidsetAge(inti){

intold;

old=age;

try{

vcSupport.fireVetoableChange("age",old,i);

age=i;

}catch(PropertyVetoExceptione){

System.out.println(e);

}

}

publicintgetAge(){

returnage;

}

publicStringgetUniversity(){

returnuniversity;

}

publicvoidsetUniversity(Strings1){

this.university=s1;

}

publicvoidaddVetoableChangeListener(VetoableChangeListenervc1){

vcSupport.addVetoableChangeListener(vc1);

}

publicvoidremoveVetoableChangeListener(VetoableChangeListenervc1){

vcSupport.removeVetoableChangeListener(vc1);

}

}

packagelab1_1;

importjava.beans.PropertyChangeEvent;

importjava.beans.PropertyVetoException;

importjava.beans.VetoableChangeListener;

publicclasstestlimitstudent{

publictestlimitstudent(){}

publicstaticvoidmain(String[]args){

limitstudentst=newlimitstudent();

System.out.println("初始信息:");

st._tostring();

st.addVetoableChangeListener(newVetoableChangeListener(){

@Override

publicvoidvetoableChange(PropertyChangeEvente)

throwsPropertyVetoException{

if(Integer.parseInt((e.getNewValue()).toString())<=20)

throw(newPropertyVetoException("年龄太小"+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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: