程序 空指针异常

d83323270 2007-12-04 10:00:00
while(true)
{
System.out.print("#");

String input = scanner.next();


if(input.equals("quit"))
break;
else
{

try{
String[] args1 = input.split(","); //以","分割字符串,split()产生的是一个字符串数组,数组元素是以split的参数为分割点分割后的字符串,按顺序从左至右.
//若被分割字符串中没有将分割的符号,则数组长度为0.
String name = args1[0]; //名字
int chengji1 = Integer.parseInt(args1[1]); //成绩
int chengji2 = Integer.parseInt(args1[2]);
int chengji3 = Integer.parseInt(args1[3]);




person =new JuniorCollegeStudent(name,chengji1,chengji2,chengji3 );

list.add(person);

//写入属性文件

AboutProperties zhuanke=new AboutProperties();
zhuanke.run1(person);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("输入格式错误");
}
}
}

提示空指针异常,是AboutProperties zhuanke=new AboutProperties();
zhuanke.run1(person);
段出了问题 而 AboutProperties类是我写的一个保存属性到属性文件的一个类
实现为:
public class AboutProperties {
//关于专科生的写入操作
public void run1(JuniorCollegeStudent a) throws IOException, IOException
{
Properties pro = new Properties();
pro.load(new FileInputStream("property.properties") );

pro.setProperty(a.GetName()+"."+"xueli", a.level);
pro.setProperty(a.GetName()+"."+"score", a.firsttest+","+a.secondtest+","+"a.thirdtest");
pro.setProperty(a.GetName()+"."+"update?", a.YesOrNo);

pro.store(new FileOutputStream("property.properties"),"comments");
}
}

请问是哪出了问题?
...全文
106 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
d83323270 2007-12-04
  • 打赏
  • 举报
回复
问题已经找到,是
pro.setProperty(a.GetName()+"."+"update?", a.YesOrNo); 中的YesOrNo没有计算出结果导致的。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧