無法真正理解這裏發生了什麼問題?異常和數組問題
這只是一個簡單的異常與數組越界。
public class Days
{
public static void main (String args[])
{
String[] dayArray = new String [4];
{
dayArray [0] = "monday";
dayArray [1] = "tuesday";
dayArray [2] = "wednesday";
dayArray [3] = "Thursday";
dayArray [4] = "Friday";
try
{
System.out.println("The day is " + dayArray[5]);
}
catch(ArrayIndexOutOfBoundsException Q)
{
System.out.println(" invalid");
Q.getStackTrace();
}
System.out.println("End Of Program");
}
}
}
沒有任何人有任何想法,也爲什麼不跑?我收到錯誤:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Days.main(Days.java:14)
它是簡單的聲明陣列5元件和您使用不存在進出結合 – SjB 2009-11-18 13:50:53