title: What is java.lang.ClassCastException: java.util.ArrayList
body: <p>My code throwing java.lang.ClassCastException exception error, Why this error will get?. I am using com.android.internal.telephony API's. i.e You can find classes I am using here Call.java<code>&lt;http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/com/android/internal/telephony/Call.java&gt;</code>, CallManger.java <code>&lt;http://hi-android.info/src/com/android/internal/telephony/CallManager.java.html&gt;</code> I have created a Subclaas of Call.java like this:</p>
  
  <pre><code>    public class MyCall extends Call{   
  
          CallManager cm = CallManager.getInstance(); 
          Phone.State state;
          Connection c;
           Phone mDefaultPhone;
           private final ArrayList&lt;Connection&gt; emptyConnections = new ArrayList&lt;Connection&gt;();    
           MyCall ringingCall;     
  
          @Override
          public List&lt;Connection&gt; getConnections() {          
              state = cm.getState();      
              ringingCall = (MyCall) cm.getRingingCalls();
              System.out.println("**inside getConnections="+ringingCall);     
              if ( ringingCall != null &amp;&amp; !ringingCall.isIdle()) {
                  System.out.println("**call is not null***");
                  return ((MyCall) ringingCall).getConnections();
              }      
              else
              {
                  System.out.println("**list is  null***");
                  return emptyConnections;
              }       
          }
  
          @Override
          public Phone getPhone() {
              // TODO Auto-generated method stub
              return null;
          }
  
          @Override
          public void hangup() throws CallStateException {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public boolean isMultiparty() {
              // TODO Auto-generated method stub
              return false;
          }
  
          public Connection
          getEarliestConnection() {
              System.out.println("inside EarliestConnection"); 
              List l;
              long time = Long.MAX_VALUE;
              Connection c;
              Connection earliest = null;
  
              l = getConnections();
  
              if (l == null) {
                  return null;
              }else if ( l.size() == 0)
              {
                  return null;
              }
  
              System.out.println("value of connection is=="+l); 
              for (int i = 0, s = l.size() ; i &lt; s ; i++) {
                  c = (Connection) l.get(i);
                  long t;
  
                  t = c.getCreateTime();
  
                  if (t &lt; time) {
                      earliest = c;
                      time = t;
                  }
              }
  
          return earliest;
      }
  }
  </code></pre>
  
  <p>I called CallManger.java like this in my own class</p>
  
  <pre><code>CallManager cm = CallManager.getInstance();
  </code></pre>
  
  <p>My another class is CallUpdate, it should give me a OutgoingCall states (i.e other side phone is Busy, Power-off, not-reachable etc.) The code is like this:</p>
  
  <pre><code>public class CallUpdate {   
  
      Call myCall = new MyCall();
      Connection myConn = new MyConnection();
      CallManager cm = CallManager.getInstance();
  
          public Object getCallFailedString(){
  
             myConn = myCall.getEarliestConnection();
             System.out.println("myConn is  ******"+myConn);
             System.out.println("myCall is  ******"+myCall);  
  
             if(myConn == null){
                  System.out.println("myConn is null ******");
                  return null;
             }                
            else
              {
                 Connection.DisconnectCause cause = myConn.getDisconnectCause();                       
                 System.out.println("myconn is not null ******"+cause);   
  
  
                  switch(cause){
  
                   case BUSY :
                     System.out.println("inside busy");
                   break;
  
                   case NUMBER_UNREACHABLE :
                      System.out.println("inside un-reachable");
                   break;
  
                  case POWER_OFF :
                     System.out.println("inside power off");
                   break;  
                }
         }
      return myConn;
   }
  </code></pre>
  
  <p>I called this class in BroadCastReceiver(). But i am getting connection is null. My code is not getting inside else part. So that I added some code in getConnection method of MyCall class like this:</p>
  
  <pre><code>public List&lt;Connection&gt; getConnections() {      
  
  
       state = cm.getState();     
       ringingCall = (MyCall) cm.getRingingCalls();
           System.out.println("**inside getConnections="+ringingCall);        
            if ( ringingCall != null &amp;&amp; !ringingCall.isIdle()) {
              System.out.println("**call is not null***");
              return ((MyCall) ringingCall).getConnections();
          }      
          else
          {
              System.out.println("**list is  null***");
              return emptyConnections;
          }   
      }
  </code></pre>
  
  <p>But I am getting java.lang.ClassCastException: on Line:
     <code>ringingCall = (MyCall) cm.getRingingCalls();</code>
  And also on <code>l = getConnection();</code> 
    How to solve this ??
  Thx in advance.</p>