0
Excel에서 숫자를 읽고 배열에 넣으려고하는데 범위를 벗어났습니다 ... Excel 파일에 열이 2 개 있고 열이 32 개 ... 숫자가 첫 번째 열 (5 자리 길이)은 allInputs라는 배열에 삽입되는 반면 두 번째 열 (3 자리 길이) 배열은 allTargets라는 배열에 삽입됩니다. 다음은 내 코드입니다.ArrayIndexOutofBoundsException 배열
String[] allInputs = new String[32];
String[] allTargets= new String[32];
//Read the values from csv file
//Input file which needs to be parsed
String fileToParse = "C:\\Users\\ROBMARYAN\\Documents\\UOM\\Bsc IT Comp & Business\\3rd Yr\\Business Intelligence\\NeuralNetAssignment\\src\\inputs.csv";
BufferedReader fileReader = null;
//Delimiter used in CSV file
final String DELIMITER = ",";
try
{
String line = "";
//Create the file reader
fileReader = new BufferedReader(new FileReader(fileToParse));
//Read the file line by line
int icount=0; //determine where to store the input
int tcount=0; //determine where to store the target
while ((line = fileReader.readLine()) != null)
{
//Get all tokens available in line
String[] tokens = line.split(DELIMITER);
for(String token : tokens)
{
//Print all tokens
if (token.length() == 5)
{
***allInputs[icount]=token***;
System.out.println("Stored in all inputs:"+allInputs[icount]);
icount++;
}
else
{
allTargets[tcount]=token;
System.out.println("Stored in all targets:"+allTargets[tcount]);
tcount++;
}
System.out.println("iCOUNT:"+icount);
System.out.println("tCOUNT:"+icount);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
여기에서 allInputs[icount]=token
인 경우 다음 오류가 발생합니다. 사전에
java.lang.ArrayIndexOutOfBoundsException: 32
감사합니다!
엑셀에 나는 5 자리 길이의 32 자리 숫자를 넣었으므로 바뀌지 않을 것입니다. 그래서 경계를 넘치지 말아야한다고 생각합니다. – user3606198
OK, 그럼 파일을 보겠습니다. 우리는 이것을 재현하고 디버깅 할 수 있습니다. –