我是編程新手,在eclipse中運行一些新代碼時,遇到了這個錯誤,並且完全丟失了。線程「main」中的異常java.lang.ArrayIndexOutOfBoundsException
import java.util.Scanner;
public class Lab6
{
public static void main(String[] args)
{
// Fill in the body according to the following comments
Scanner in= new Scanner(System.in);
// Input file name
String FileName=getFileName(in);
// Input number of students
int numOfStudents = FileIOHelper.getNumberOfStudents(FileName);
Student students[] = getStudents(numOfStudents);
// Input all student records and create Student array and
// integer array for total scores
int[]totalScores = new int[students.length];
for(int i=0; i< students.length; i++)
{
for(int j=1; j<4; j++)
{
totalScores[i]= totalScores[i]+students[i].getScore(j);
}
}
// Compute total scores and find students with lowest and
// highest total score
int i;
int maxIndex =0;
int minIndex =0;
for(i=0; i<students.length; i++);
{
if(totalScores[i]>=totalScores[maxIndex])
{
maxIndex=i;
}
else if(totalScores[i]<=totalScores[minIndex])
{
minIndex=i;
}
}
問題似乎是在該行如果(totalScores [I]> = totalScores [maxIndex])
堆棧跟蹤(與你的ArrayIndexOutOfBoundsException異常開始)的前幾行是至關重要的。 – Satya 2011-03-03 03:42:11
你的代碼中的另一個錯誤是;之後的for()。 – Mudassir 2011-03-03 03:47:21