Results 1 to 2 of 2
  1. #1
    Lets Assume is offline Assuming
    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Default Error: java.lang.ArrayIndexOutOfBoundsException

    I have searched the internet to try and find a solution to this, but I can't seem to find one anywhere. Any help is greatly appreciated.

    ERROR:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
    at Sample25.<init>(Sample25.java:58)
    at Sample25.main(Sample25.java:97)


    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Sample25 extends JFrame implements ActionListener
    {
        private String[] games = {
                "", "Battlefield Bad Company 2", "Battlefield 3", "Borderlands 2", "Call of Duty 3",
                "Call of Duty 4", "Call of Duty: Black Ops 1", "Call of Duty: Black Ops II",
                "Call of Duty: Modern Warfare 2", "Call of Duty: Modern Warfare 3", "Call of Duty: World at War",
                "Crysis 2", "Gears of War 3", "Gears of War Judgment", "Halo Reach", "Halo 4",
                "Medal of Honor", "Medal of Honor: Warfighter", "Minecraft", "Red Dead Redemption"
              };
        private String[] gameTypeList = {
                "", "Gaming", "Boosting", "Zombies", "Spec Ops", "Horde"
              };
    
        
      JLabel L1 = new JLabel("BrettLiekzBananaz",JLabel.CENTER);
      JLabel L2 = new JLabel("Select a Game:",JLabel.CENTER);
      JLabel L3 = new JLabel("Select a Game Type:",JLabel.CENTER);
      
      JComboBox game = new JComboBox();
      JComboBox gameType = new JComboBox();
      
      JTextField T1 = new JTextField();
      JTextField T2 = new JTextField();
      JTextField T3 = new JTextField();
      JTextField T4 = new JTextField();
      JTextField T5 = new JTextField();
      JTextField T6 = new JTextField();
      JTextField T7 = new JTextField();
      JTextField T8 = new JTextField();
      JTextField T9 = new JTextField();
      JTextField T10 = new JTextField();
      JTextField T11 = new JTextField();
      JTextField T12 = new JTextField();
      JTextField T13 = new JTextField();
      private int count = 0;
        
      //start activation for button here 
      public void button_B1()
      {
        
      }
      //stop activation of button
        
        
    //do not copy below this point por favor  
      public Sample25() 
      {
        super("BrettLiekzBananaz");
        Container container = getContentPane(); 
        setSize(500,500);
        setLayout(new GridLayout(7,1));
        for(int i = 0; i < games.length; i++)
               game.addItem(games[count++]);
        
        for(int k = 0; k < gameTypeList.length; k++)
               gameType.addItem(gameTypeList[count++]); 
        
          
        JPanel JPanel1 = new JPanel();
        JPanel1.setLayout(new GridLayout(1, 1));
        JPanel1.setBackground(Color.white);
        JPanel1.add(L1);
        container.add(JPanel1);
          
        JPanel JPanel2 = new JPanel();
        JPanel2.setLayout(new GridLayout(1, 1));
        JPanel2.setBackground(Color.white);
        JPanel2.add(L2);
        JPanel2.add(game);
        container.add(JPanel2);
          
        JPanel JPanel3 = new JPanel();
        JPanel3.setLayout(new GridLayout(1, 1));
        JPanel3.setBackground(Color.white);
        JPanel3.add(L3);
        JPanel3.add(gameType);
        container.add(JPanel3);
          
          
          
          
        //stop adding here
        setVisible(true);
      }
        
      /* activate buttons and textfields here */
      public void actionPerformed(ActionEvent e)
      {
          
        //if (e.getSource() == B1) button_B1();
          
      }
        
      public static void main(String args[]) {
        Sample25 prog = new Sample25();
        prog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }  
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: Error: java.lang.ArrayIndexOutOfBoundsException

    Probably lines 55-59, you didn't reset count to 0 for the second loop. But why are you using the variable "count" and not the loop variable?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 5
    Last Post: 07-25-2012, 04:11 PM
  2. java.lang.ArrayIndexOutOfBoundsException ERROR?
    By dharav in forum New To Java
    Replies: 5
    Last Post: 01-15-2012, 09:33 AM
  3. Replies: 4
    Last Post: 10-02-2011, 08:29 PM
  4. Replies: 1
    Last Post: 09-27-2011, 06:47 PM
  5. Replies: 1
    Last Post: 07-31-2007, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •