我新的Java和我遇到的是真實吹我的腦海裏一個錯誤......錯誤是:錯誤的readLine()的Java讀錯行
Exception in thread "main" java.lang.NullPointerException
at BancA.carica(BancA.java:30)
at BancA.main(BancA.java:46)
我需要裝載從一些值txt文件......這是由ID(Cliente1等),數(支付)的第一列表,第二個(傳輸)組成......我已經決定要區分這兩種類別的劃分它們通過「 - 」 ......但的readLine()似乎讀錯線,或者無視我的「而」語句......反正這是我的代碼,你的幫助,我們會如此讚賞:-)
import java.io.*;
import java.util.*;
import java.lang.*;
public class BancA{
private static final String CLIENTI = ("Clienti.txt");
private static ArrayList <Conto> conto = new ArrayList <Conto>();
public static void carica(){
BufferedReader bc;
Conto co = new Conto();
String tmp, tmp1, tmp2;
try{
bc = new BufferedReader(new FileReader(CLIENTI));
tmp = bc.readLine();
while(tmp!=null){
co.setId(tmp);
tmp1 = bc.readLine();
while(!(tmp1.equals("-"))){
co.setBonifico(Integer.parseInt(tmp1));
tmp1 = bc.readLine();
}
tmp2 = bc.readLine();
while(!(tmp2.equals("-"))){
co.setVersamento(Integer.parseInt(tmp2));
tmp2 = bc.readLine();
}
conto.add(co);
co = new Conto();
tmp = bc.readLine();
}
System.out.println(conto);
}
catch(IOException e){
e.printStackTrace();
}
}
public static void main(String [] args){
carica();
}
}
,這是其他類:
import java.util.*;
public class Conto{
public String id;
public LinkedList <Integer> bonifico = new LinkedList <Integer>();
public LinkedList <Integer> versamento = new LinkedList <Integer>();
public Conto(){
}
public void setId(String i){
id = i;
}
public void setBonifico(int b){
bonifico.add(b);
}
public void setVersamento(int v){
versamento.add(v);
}
public String getId(){
return id;
}
public LinkedList <Integer> getBonifico(){
return bonifico;
}
public LinkedList <Integer> getVersamento(){
return versamento;
}
public String toString(){
String str = ("\nId: " +id+ "\nBonifico: " +bonifico+ "\nVersamento:+versamento);
return str;
}
}
,而這是我的Clienti.txt文件:
Cliente1
1
2
3
-
41
52
33
90
-
Cliente2
4
-
89
3
1
哪裏是線30? –