Re: ArrayIndexOutOfBoundsException confusion
On 2007-01-11, phillip.s.powell@gmail.com <phillip.s.powell@gmail.com> wrote:
private final String[] buttonNameArray = {"cButton", "ceButton",
"percentButton", "sqrtButton", "plusButton", "mcButton", "button7",
"button8",
"button9", "dashButton", "mrButton", "button4", "button5",
"button6",
"starButton", "mDashButton", "button1", "button2", "button3",
"slashButton",
"mPlusButton", "plusDashButton", "dotButton", "button0",
"equalButton"};
private final String[] buttonValArray = {"CE", "%", "\u221a", "+",
"MC", "7", "8", "9", "-", "MR", "4", "5", "6", "*", "M-", "1", "2",
"3", "/",
"M+", "+/-", ".", "0", "="};
private Hashtable buttonHash = null;
private void initComponents() {
this.buttonHash = new Hashtable();
for (int i = 0; i < this.buttonNameArray.length; i++) {
this.buttonHash.put(this.buttonNameArray[i],
this.buttonValArray[i]);
}
}
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 24
at JCalculator.initComponents(JCalculator.java:44)
at JCalculator.<init>(JCalculator.java:32)
at JCalculator.main(JCalculator.java:66)
Java Result: 1
How on earth is this spawning an ArrayIndexOutOfBoundsException? I
don't see how that is possible as the array pointer should be at 0 and
there are a lot more than 0 elements in the final array.
Help appreciated, I am totally not understanding.
The exception message is complaining an index value of 24 begin out of
bounds. What are the values of buttonNameArray.length and
buttonValArray.length?