title: How to fix java.lang.ClassCastException Android
body: <p>I have searching for this case, i found it but in C#. Oke, I try to show my data into the listview using ListFragment android, json and mysql, but i got an error Class Cast when I running it, i hope anyone can help me.
  Here My Error :</p>
  
  <pre><code>06-12 17:04:04.685 20975-20975/com.spp.udi.sppmap E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: com.spp.udi.sppmap, PID: 20975
                                                                      java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.spp.udi.sppmap/com.spp.udi.sppmap.Potensi}: java.lang.ClassCastException: com.spp.udi.sppmap.Potensi cannot be cast to android.app.Activity
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
                                                                          at android.app.ActivityThread.access$900(ActivityThread.java:153)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5451)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                       Caused by: java.lang.ClassCastException: com.spp.udi.sppmap.Potensi cannot be cast to android.app.Activity
                                                                          at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2335)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
                                                                          at android.app.ActivityThread.access$900(ActivityThread.java:153) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:148) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5451) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>
  
  <p>My Potensi.java :</p>
  
  <pre><code>package com.spp.udi.sppmap;
  
  import android.app.Fragment;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ListView;
  import android.app.ListFragment;
  import java.util.ArrayList;
  import java.util.HashMap;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  import android.util.Log;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListAdapter;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  
  public class Potensi extends ListFragment {
      private static final String ID_KECAMATAN = "id_kecamatan";
      private static final String NAMA_KECAMATAN = "nama_kecamatan";
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          JSONObject json = JSONFunction.getJSONFromUrl("http://192.168.43.203/project/s9/udi/android/potensi.php");
          try {
              JSONArray laporan = json.getJSONArray("result");
              for(int i=0; i&lt;laporan.length(); i++){
                  JSONObject jsonobj = laporan.getJSONObject(i);
                  String id_kecamatan = jsonobj.getString(ID_KECAMATAN);
                  String nama_kecamatan = jsonobj.getString(NAMA_KECAMATAN);
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                  map.put("id_kecamatan", id_kecamatan);
                  map.put("nama_kecamatan", nama_kecamatan);
                  mylist.add(map);
              }
          } catch (JSONException e) {
              Log.e("log_tag","error parsing data "+e.toString());
          }
          this.adapter_listview();
      }
  
      public void adapter_listview() {
          ListAdapter adapter = new SimpleAdapter(getActivity(), mylist, R.layout.potensi,
                  new String[] {ID_KECAMATAN, NAMA_KECAMATAN}, new int[] {R.id.id_kecamatan, R.id.nama_kecamatan});
  
          setListAdapter(adapter);
          ListView lv = getListView();
          lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,int position, long id) {
                  String id_kecamatan = ((TextView) view.findViewById(R.id.id_kecamatan)).getText().toString();
                  Intent in = new Intent(getActivity(), DetailPotensi.class);
                  in.putExtra(ID_KECAMATAN, id_kecamatan);
                  startActivity(in);
              }
          });
      }
  }
  </code></pre>
  
  <p>My output json :</p>
  
  <pre><code>{"result":[{"id_kecamatan":"8","nama_kecamatan":"Batang Dua"},{"id_kecamatan":"7","nama_kecamatan":"Pulau Moti"},{"id_kecamatan":"6","nama_kecamatan":"Pulau Hiri"},{"id_kecamatan":"5","nama_kecamatan":"Pulau Ternate"},{"id_kecamatan":"4","nama_kecamatan":"Ternate Utara"},{"id_kecamatan":"3","nama_kecamatan":"Ternate Tengah"},{"id_kecamatan":"2","nama_kecamatan":"Ternate Selatan"}]}
  </code></pre>