Java ArrayList Out of Bounds Exeption -


i making blackjack game (non gui) , write algorithms decide whether receive card, how bet, etc. receiving out of bounds error on arraylist when adding values. thank help.

    package idk;      import java.util.arraylist;     import java.util.collections;     import java.util.random;      public class {     public static void main(string[] args) {     something = new something();     arraylist<integer> place=new arraylist<integer>();     int i;     for(i=0; i<4; i++)     {         place.add(2);     }     for(i=4; i<8; i++)     {         place.add(3);     }     for(i=8; i<12; i++)     {         place.add(4);     }     for(i=12; i<16; i++)     {         place.add(5);     }     for(i=16; i<20; i++)     {         place.add(6);     }     for(i=20; i<24; i++)     {         place.add(7);     }     for(i=24; i<28; i++)     {         place.add(8);     }     for(i=28; i<32; i++)     {         place.add(9);     }     for(i=32; i<48; i++)     {         place.add(10);     }     for(i=48; i<52; i++)     {         place.add(11);     }     for(i=0; i<52; i++)     {         system.out.println(place.get(i));     }     int[] dealer;     dealer = new int[28];     for(int w=0; w<2; w++)     {      int min = 0;         int max = 52;        int range = (max - min);          int random = new random().nextint(range + 1) + min;        int card = place.get(random);        dealer[i]=card;        place.remove(random);        if(i==1)        {            system.out.println("the dealer's face card " + card);        }      }        } 

}

the issue line dealer[i]=card;

check value of i, greater declared size of dealer[].

after last for loop i, value of i 52, , dealer[] size 28.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -