标题:javaweb问题求解
取消只看楼主
瞬间永恒
Rank: 1
等 级:新手上路
帖 子:2
专家分:4
注 册:2014-4-2
结帖率:100%
已结贴  问题点数:20 回复次数:0 
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)
搜索更多相关主题的帖子: university package javaweb public import 
2014-04-02 14:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-429554-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.061074 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved