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");
}
}请问是哪出了问题?
{
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");
}
}请问是哪出了问题?
pro.setProperty(a.GetName()+"."+"update?", a.YesOrNo); 中的YesOrNo没有计算出结果导致的。