我是编程新手,在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