| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 471 人关注过本帖
标题: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
快速回复:javaweb问题求解
数据加载中...
 
   



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

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