Display list of active(running) applications in a list view
<p>Hi I am trying to write an application that displays the list of running applications. I used activity manager for that. While running the application, It is showing the following error."UNHANDLED EVENT LOOP EXECUTION" IN ERROR LOG and application is force closing.</p>

<p>Please help me to find my mistake.
My code is given below.</p>

<pre><code>package com.android.taskmanager.activeapplications;

import java.util.List;
import android.app.ActivityManager;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ActiveApplicationsActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); 
    List&lt;ActivityManager.RunningAppProcessInfo&gt; l = am.getRunningAppProcesses();

    String[] sl = (String[]) l.toArray();

    ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
            android.R.layout.simple_list_item_1,sl);

    setListAdapter(adapter);

  }

@Override
protected void onListItemClick(ListView l,View v,int position, long id){
    String item = (String)getListAdapter().getItem(position);
    Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();

  }
}
</code></pre>

<p>I am adding the logcat information</p>

<p>02-01 10:52:47.790: D/AndroidRuntime(333): Shutting down VM<br>
02-01 10:52:47.790: W/dalvikvm(333): threadid=1: thread exiting with uncaught exception (group=0x40015560)<br>
02-01 10:52:47.811: E/AndroidRuntime(333): FATAL EXCEPTION: main<br>
02-01 10:52:47.811: E/AndroidRuntime(333): java.lang.RuntimeException: Unable to start activity ComponentInfo   {com.msat.sd102268.taskmanager.activeapplications/com.msat.sd102268.taskmanager.activeapplications.ActiveApplicationsActivity}: java.lang.ClassCastException: [Ljava.lang.Object;<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.os.Handler.dispatchMessage(Handler.java:99)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.os.Looper.loop(Looper.java:123)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.main(ActivityThread.java:3683)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at java.lang.reflect.Method.invokeNative(Native Method)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at java.lang.reflect.Method.invoke(Method.java:507)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at dalvik.system.NativeStart.main(Native Method)<br>
02-01 10:52:47.811: E/AndroidRuntime(333): Caused by: java.lang.ClassCastException: [Ljava.lang.Object;<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at com.msat.sd102268.taskmanager.activeapplications.ActiveApplicationsActivity.onCreate(ActiveApplicationsActivity.java:23)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)<br>
02-01 10:52:47.811: E/AndroidRuntime(333):  ... 11 more  </p>
