title: Display list of active (running) applications in a list view
body: <p>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>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>
  
  <pre>
  02-01 10:52:47.790: D/AndroidRuntime(333): Shutting down VM  
  02-01 10:52:47.790: W/dalvikvm(333): threadid=1: thread exiting with uncaught exception (group=0x40015560)  
  02-01 10:52:47.811: E/AndroidRuntime(333): FATAL EXCEPTION: main  
  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;  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.os.Handler.dispatchMessage(Handler.java:99)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.os.Looper.loop(Looper.java:123)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.main(ActivityThread.java:3683)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at java.lang.reflect.Method.invokeNative(Native Method)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at java.lang.reflect.Method.invoke(Method.java:507)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at dalvik.system.NativeStart.main(Native Method)  
  02-01 10:52:47.811: E/AndroidRuntime(333): Caused by: java.lang.ClassCastException: [Ljava.lang.Object;  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at com.msat.sd102268.taskmanager.activeapplications.ActiveApplicationsActivity.onCreate(ActiveApplicationsActivity.java:23)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)  
  02-01 10:52:47.811: E/AndroidRuntime(333):  ... 11 more  
  </pre>