-1
급여가 int 인 CSV 파일 (이름, 성, DateOfBirth, SSN, 역할, 급여, 우편 번호, 전화 번호)으로 직원 정보를 입력하려고합니다. 유일한 문제는이 코드를 구현하려고 할 때마다NumbersFormatException이 배열리스트에 있음
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class Driver {
//Delimiters used in the CSV file
private static final String COMMA_DELIMITER = ",";
public static void main(String args[])
{
BufferedReader br = null;
try
{
//Reading the csv file
br = new BufferedReader(new FileReader("data.csv"));
//Create List for holding Employee objects
List<Employee> empList = new ArrayList<Employee>();
String line = "";
//Read to skip the header
br.readLine();
//Reading from the second line
while ((line = br.readLine()) != null)
{
String[] employeeDetails = line.split(",");
//Save the employee details in Employee object
Employee emp = new Employee(employeeDetails[0],employeeDetails[1],
employeeDetails[2],
employeeDetails[3],
employeeDetails[4],
Integer.parseInt(employeeDetails[5]),
employeeDetails[6],
employeeDetails[7]);
empList.add(emp);
}
for(int i = 0;i<empList.size();i++){
System.out.println(empList);
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
finally{
try{
br.close();
}
catch(IOException ie){
System.out.println("Error occured while closing the BufferedReader");
ie.printStackTrace();
}
}
}
}
오류가 발생합니다. NumbersFormatException 오류가 발생합니다. 직원 클래스는 생성자 setters 및 getters로 만들어졌습니다.
방금 CSV를 검색했습니다. 저의 혼란의 뿌리는 항상 봉급이 있습니다.
나던 있는 Integer.parseInt ([5] employeeDetails가) 실패 :
분명히 'employeeDetails [5]'는 항상 숫자는 아닙니다. – shmosel
그럼 어떻게해야합니까? – Frogrammer
무엇을 하시겠습니까? – shmosel