我有以下錯誤:錯誤ArrayIndexOutOfBoundsException異常
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
1 at test.Main.main(Main.java:28)
我是初學者,我也沒有真正理解的東西被stucked。我認爲在for
的某個地方。
有些幫助請問?
主類
public static ArrayList<Patron> patr_list= new ArrayList<Patron>();
public static ArrayList<Angajat> angj_list= new ArrayList<Angajat>();
public static ArrayList<Persoana> pers_list = new ArrayList<Persoana>();
public static void main(String []args) throws Exception
{
BufferedReader flux_in= new BufferedReader (new InputStreamReader (new FileInputStream("C:/Users/Administrator/workspace/test/test.txt")));
String linie;
while((linie= flux_in.readLine()) != null)
{
String [] s;
s= linie.split(";");
if(linie.contains("angajat"))
{
angj_list.add(new Angajat(s[0], Integer.parseInt(s[1]), Calendar.getInstance(), s[3], s[4]));
}
else
if(linie.contains("patron"))
{
patr_list.add(new Patron(s[0], Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3])));
}
pers_list.addAll(patr_list);
pers_list.addAll(patr_list);
System.out.println(String.format("Nume", "Varsta", "Data_angajarii", "Loc de munca", "Functia"));
for(Angajat angj: angj_list)
{
System.out.println(angj);
}
System.out.println(String.format("Nume", "Varsta", "Nr de firme", "Nr de angajti"));
for(Patron patr: patr_list)
{
System.out.println(patr);
}
}
}
}
單人牀CLASS
public String nume;
public int varsta;
public Persoana (String nume, int varsta)
{
this.nume=nume;
this.varsta=varsta;
}
公共字符串getNume(){
返回nume;
}
public void setNume(String nume)
{
this.nume = nume;
}
public int getVarsta()
{
return varsta;
}
public void setVarsta(int varsta)
{
this.varsta = varsta;
}
}
贊助CLASS
public int nr_firme;
public int nr_angajati;
public Patron(String nume, int varsta, int nr_firme, int nr_angajati)
{
super(nume,varsta);
this.nr_firme=nr_firme;
this.nr_angajati=nr_angajati;
}
public int getNr_firme()
{
return nr_firme;
}
public void setNr_firme(int nr_firme)
{
this.nr_firme = nr_firme;
}
public int getNr_angajati()
{
return nr_angajati;
}
public void setNr_angajati(int nr_angajati)
{
this.nr_angajati = nr_angajati;
}
public String toString()
{
return "Patronul are" + nr_firme + "firme si" + nr_angajati+ "numar de angajti";
}
Angajat CLASS
public Calendar data_angajarii;
public String loc_munca;
public String functie;
public Angajat(String nume, int varsta, Calendar data_angajarii, String loc_munca, String functie)
{
super(nume, varsta);
this.data_angajarii=data_angajarii;
this.loc_munca=loc_munca;
this.functie=functie;
}
public Calendar getData_angajarii()
{
return data_angajarii;
}
public void setData_angajarii(Calendar data_angajarii)
{
this.data_angajarii = data_angajarii;
}
public String getLoc_munca()
{
return loc_munca;
}
public void setLoc_munca(String loc_munca)
{
this.loc_munca = loc_munca;
}
public String getFunctie()
{
return functie;
}
public void setFunctie(String functie)
{
this.functie = functie;
}
public String toString()
{
return "Angajatul a fost angajat in data de" + data_angajarii + "lucreaza la " + loc_munca+ " si are functia de " + functie;
}
文本文件
angajat ionel 16 1991,8.4 timisoara director;
顧客gigel 45 100 5000;
究竟哪一條線是28? –
請提供完整的源文件,包括類+包聲明和導入聲明。代碼片段中的第28行是一個空行。或者,在上例中拋出異常的高亮或粗體行。 – user2910265
請提供您的文本文件的一個片段。 –