帮我一下
我的类
public class Account {
private int deposit;//存款
private int sno;//账户号码
private int smm;//账号密码
private String sname;//账户名
public Account(){}
public Account(int x,int y,int z,String g){
deposit=x;
sno=y;
smm=z;
sname=g;
}
public int getDeposit() {
return deposit;
}
public void setDeposit(int deposit) {
this.deposit = deposit;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public int getSmm() {
return smm;
}
public void setSmm(int smm) {
this.smm = smm;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String tostring(){
return ("名字为:"+sname+"开了账户号为:"+sno+"密码为:"+smm+"存款余额为:"+deposit);
}
}
存入文件什么的
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Accountrun{
private Account a;
public Account geta() {
return a;
}
public void seta(Account a) {
this.a = a;
}
public Accountrun(){}
public Accountrun(Account x){
a=x;
}
public void create(Account a) throws IOException{
FileWriter f=new FileWriter("G://java/daima/717/aa.txt",true);
f.write(a.toString()+"\r\n");
f.flush();
f.close();
}
public Account[] quchu() throws IOException{
FileReader f=new FileReader("G://java/daima/717/aa.txt");
BufferedReader bre=new BufferedReader(f);
Account[] a=new Account[100];
String str="";
try {
for(int i=0;(str=bre.readLine())!=null;i++) //判断最后一行不存在,为空
{
//这边我的理解是匹配“:”和“;”中间的字符串(算是正则??)
Pattern p=Pattern.compile(":(\\w+);");
//建设实例
Matcher m=p.matcher(str);
a[i].setSname(m.group(1));
a[i].setSno(Integer.parseInt(m.group(1)));
a[i].setSmm(Integer.parseInt(m.group(1)));
a[i].setDeposit(Integer.parseInt(m.group(1)));
//这两个是区别带不带之前的边界
//System.out.println(m.group(0));
//System.out.println(m.group(1));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bre.close();
return a;
}
public static void main(String[] args) throws IOException
{
Accountrun r=new Accountrun();
Account[] a=r.quchu();
for(int i=0;i<a.length;i++)
{
System.out.println(a[i].getSno()+a[i].getSname());
}
}
}
报错
Exception in thread "main" java.lang.NullPointerException
at Accountrun.quchu(Accountrun.java:38)
at Accountrun.main(Accountrun.java:59)