title: Class Cast Exception when passing array of Serializables from one activity to another
body: <p>I have an array containing serializable objects and am trying to use Intent's putExtra() and Bundle's getSerializable().  However, I am getting a class cast exception and don't understand why. </p>
  
  <p>Below is the code.  UserInfo is my own class which implements Serializable, and I have been able to pass individual UserInfo objects between activities.  I've only ran into this problem when attempting to use an array.</p>
  
  <p><strong>Code sending the serializable:</strong></p>
  
  <pre><code>Intent intent = new Intent( JOIN_GROUP ); //JOIN_GROUP is a constant string
  
  String user_ids[] = packet.userIDs();
  
  int length = user_ids.length;
  UserInfo users[] = new UserInfo[length];
  
  for ( int i = 0; i &lt; length; ++i )
      users[i] = getUserByID( user_ids[i] );
  
  intent.putExtra( USERS_IN_GROUP, users );
  </code></pre>
  
  <p><strong>Code retrieving the serializable:</strong></p>
  
  <pre><code>Bundle extra = intent.getExtras();          
  String action = intent.getAction();
  
  if ( action.equals(IMService.JOIN_GROUP) )
  {   
      //CLASS CAST EXCEPTION
      UserInfo users[] = (UserInfo[]) extra.getSerializable( IMService.USERS_IN_GROUP ); 
  }
  </code></pre>
  
  <p>Here is the error:</p>
  
  <p><img src="https://i.stack.imgur.com/fDIM1.png" alt="enter image description here"></p>
  
  <p><strong>Question</strong></p>
  
  <p>I'm aware I could probably just use a different data structure, but I would like to understand why the array does not work since arrays are serializable?</p>
  
  <p><strong>EDIT:</strong> SnyersK was able to get a simpler but similar scenario to work. 
  So I tried the same thing, and I still get the same exception.  It turned my array of Tests into an Object when retrieving the array, which results in the casting exception.</p>
  
  <p><strong>My Test object:</strong></p>
  
  <pre><code>package types;
  
  import java.io.Serializable;
  
  public class Test implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      private String hello = "hello";
  
  }
  </code></pre>
  
  <p><strong>Code to pass the array of Test objects:</strong></p>
  
  <pre><code>Test myArray[] = new Test[] { new Test(), new Test() };
  Intent i = new Intent( this, Login.class );
  i.putExtra( "key", myArray );
  </code></pre>
  
  <p><strong>Code to retrieve the array of Test objects:</strong></p>
  
  <pre><code>Bundle extras = getIntent().getExtras();
  Test array[] = (Test[]) extras.getSerializable( "key" ); //Class Cast Exception
  </code></pre>