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)
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)
相关文章推荐
- LeetCode | Search in Rotated Sorted Array
- spring的AOP面向切面编程
- c2java 第3篇 红黑树删除的理解和jdb调试初步(2014.04.03更新)
- Java反射机制(2)
- LeetCode | Longest Valid Parentheses
- java反射机制(1)
- Spring Data JPA 简单介绍
- Eclipse代码自动补全设置
- Java正则表达式较验手机号、邮箱
- 基于ajax二级联动
- java百问总结(四)
- java replaceall 用法:处理特殊字符
- java replaceall 用法:处理特殊字符
- java replaceall 用法:处理特殊字符
- java web几种开发模式
- java文件下载
- 关于Java奇数最后一个字符输出乱码问题
- 状态模式
- [java]下拉框显示图文详情
- java中HashMap详解