1 2 Previous Next 20 Replies Latest reply on Feb 15, 2009 11:46 PM by 800423

    Array Index Out of Bounds Expeception

      Hi Guys,

      I'm having trouble with a method which takes an array of objects and increases its length by one. I'm doing this by calling a method that looks at the length of the array, makes a new array with the length + 1, copies all the objects from the old to the new array. It then returns the new array overwriting the new one. This works find and if I system.out.println the length of the new array its value is 7 which is 1 more than before. The problem im having is that when i try and add stuff to an object in the array I get the index our of bound exception: 7.

      The code is as follows:
      void newcustomer(){
           int len = 0;
           int newcustomerID = 0;
           customerarray = addcustomer(customerarray);
           len = customerarray.length;
           System.out.println("Enter Customer ID: ");     
           newcustomerID = in.readInteger();
      public Customer[] addcustomer ( Customer[] oldarray ){
           int len = 0;
           len = customerarray.length;
           Customer newcustomerArray[] = new Customer[len];
           for (int i=0; i<oldarray.length; i++){
                oldarray[i] = newcustomerArray;
      Many Thanks!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        1 2 Previous Next