import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class gTextFile {
static LinkedList<gText> list = new LinkedList<gText>();
public static void main(String[] args) throws FileNotFoundException {
Scanner scnOne = new Scanner(System.in);
String eCode;
System.out.print("Employee Code: ");
eCode = scnOne.nextLine();
readFile();
gEmpName("eCode");
}
public static void readFile() throws FileNotFoundException {
File nFile = new File("C:\\JAVAP\\GetTextFile\\employee.txt");
Scanner scnTwo = new Scanner(nFile);
String oTemp;
while(scnTwo.hasNext()) {
oTemp = scnTwo.next();
String EmCode[] = oTemp.split(" ");
String Name[] = EmCode[1].split(",");
String idCode = EmCode[0];
String lastname = Name[0];
String firstname = Name[1];
//System.out.println("FName " + firstname);
//System.out.println("LName " + lastname);
gText gT = new gText(firstname, lastname, idCode);
list.add(gT);
}
scnTwo.close();
}
public static void gEmpName(String EmpCode) {
Iterator<gText> itr = list.iterator();
while(itr.hasNext()) {
gText gT = itr.next();
if(gT.id.equals(EmpCode)){
System.out.println("Employee Name: " + gT.Fname + " " + gT.Lname);
}
}
}
}
public class gText {
String Fname;
String Lname;
String id;
gText(String First, String Last, String ID) {
this.Fname = First;
this.Lname = Last;
this.id = ID;
}
public String gFName() {
return Fname;
}
public String gLName() {
return Lname;
}
public String gId() {
return id;
}
}
What are the problem in my code?? the specific code doesn't show out when I run my program. It always say that there are problem. This always come out in the console, when I put the Employee Code. Employee Code: A11-0001 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at gTextFile.readFile(gTextFile.java:28) at gTextFile.main(gTextFile.java:17)