Sunday 15 February 2015

java - I have an IndexOutOfBoundsException and can't figure out why -


I have IndexOutOfBoundsException , and I do not know why.

I have several text fields (integer, double, and others) and I want them to call ArrayList < String & gt; But the information must be used accordingly. Tag Content

This is my code:

  jLabelAL = new arreelist & lt; & Gt; (); JTextFieldAL = New ArrayList & lt; & Gt; (); For (int i = 0; i & lt; size; i ++) {jlabel.ed. (new jlabel ("++ tagassamic.ast (i))"; switch (tag contentant.lit (i) .toString ( Case "Double": Case "Float": jTextFieldAL.add (JTextField) new tool. DoubleTextField (Simulation) ); Break;; "jtextFieldAL.add (JTextField) new JTextField (); breakdown;} JTextFieldAL.get (i) .addKeyListener (keyEvent); // IndexOutOfBoundsException p1.add (jLabelAL.get) in this line (I)); p1.add (jTextFieldAL.get (i));}   

What's the problem?

Not It is a matter of course that you are adding an element on each iteration to jTextFieldAL , since there is no default case in the switch if you have not added a code to jTextFieldAL , Then every one of the present is to run again, and when you have jTextFieldD.get (i) , the last element (if any) has an index i < / Code>. In practice, this means that you will get the first IndexOutOfBoundsException at the frequency of the code in which you are unable to add an element to jTextFieldAL .

No comments:

Post a Comment