title: Android custom listView click - how to call an intent to another activity
body: <p>Some one help please. I'm trying to create an app with a custom list view which has text view and image view. the list items are filtered and on clicking on the list item it should open up an associated activity. However the app crashes when i click on an item giving message,"thread exiting with uncaught exception". Here are my codes.</p>
  
  <blockquote>
    <p>main.java</p>
  </blockquote>
  
  <pre><code>package com.example.lenovo.filterapp;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.AdapterView;
  import android.widget.ListView;
  import android.widget.SearchView;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  public class MainActivity extends AppCompatActivity {
  
      ListView lv;
      SearchView sv;
  
      String[] names = {"Lionel Messi","Christiano Ronaldo","Neymar JNR","Luis Suarez"};
      int[] images ={R.drawable.badge,R.drawable.bucky,R.drawable.dentala,R.drawable.house};
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          lv = (ListView) findViewById(R.id.listView);
          sv = (SearchView) findViewById(R.id.searchView);
  
          //Adapter
          final Adapter adapter = new Adapter(this,getPlayers());
          lv.setAdapter(adapter);
  
          sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String s) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String query) {
  
                  adapter.getFilter().filter(query);
                  return false;
              }
          });
  
          final HashMap&lt;String, Class&gt; hashMap=new HashMap&lt;String, Class&gt;();
  
  
          hashMap.put("Lionel Messi",Lionel.class);
          hashMap.put("Christiano Ronaldo",Christiano.class);
          hashMap.put("Neymar JNR",Neymar.class);
          lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
                  String openClass = (String) adapter.getItem(position);
                  Intent myIntent1 = new Intent(MainActivity.this,
                          hashMap.get(openClass));
                  startActivity(myIntent1);
              }
  
          });
  
      }
  
      private ArrayList&lt;Player&gt; getPlayers(){
          ArrayList&lt;Player&gt; players = new ArrayList&lt;Player&gt;();
          Player p;
  
          for (int i = 0;i&lt;names.length;i++){
              p = new Player(names[i],images[i]);
              players.add(p);
          }
          return players;
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Adapter.java</p>
  </blockquote>
  
  <p>package com.example.lenovo.filterapp;</p>
  
  <pre><code>import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.Filter;
  import android.widget.Filterable;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  
  /**
   * Created by LENOVO on 2/6/2016.
   */
  public class Adapter extends BaseAdapter implements Filterable{
      Context c;
      ArrayList&lt;Player&gt; players;
      CustomFilter filter;
      ArrayList&lt;Player&gt; filterList;
  
      public Adapter(Context c, ArrayList&lt;Player&gt; players) {
          this.c = c;
          this.players = players;
          this.filterList = players;
      }
  
      @Override
      public int getCount() {
          return players.size();
      }
  
      @Override
      public Object getItem(int position) {
          return players.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return players.indexOf(getItem(position));
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) c.getSystemService(c.LAYOUT_INFLATER_SERVICE);
  
          if(convertView == null){
              convertView= inflater.inflate(R.layout.activity_customrow,null);
          }
  
          TextView nameTxt = (TextView) convertView.findViewById(R.id.buckysTextView);
  
          ImageView img = (ImageView) convertView.findViewById(R.id.alisImageView);
  
          //Set data to them
          nameTxt.setText(players.get(position).getName());
          img.setImageResource(players.get(position).getImg());
          return convertView;
      }
  
      @Override
      public Filter getFilter() {
  
          if(filter == null){
              filter = new CustomFilter();
          }
          return filter;
      }
  
      //Inner Class
      class CustomFilter extends Filter{
  
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
  
              FilterResults results = new FilterResults();
  
              if(constraint != null &amp;&amp; constraint.length()&gt;0){
                  //Constraint to Upper
                  constraint = constraint.toString().toUpperCase();
  
                  ArrayList&lt;Player&gt; filters = new ArrayList&lt;Player&gt;();
  
                  //get specific Items
                  for (int i =0;i&lt;filterList.size();i++){
  
                      if(filterList.get(i).getName().toUpperCase().contains(constraint)){
                          Player p = new Player(filterList.get(i).getName(),filterList.get(i).getImg());
  
                          filters.add(p);
                      }
                  }
                  results.count = filters.size();
                  results.values = filters;
              }
              else {
                  results.count = filterList.size();
                  results.values = filterList;
              }
  
              return results;
          }
  
          @Override
          protected void publishResults(CharSequence constraint, FilterResults results) {
  
              players = (ArrayList&lt;Player&gt;) results.values;
              notifyDataSetChanged();
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Player.java</p>
  </blockquote>
  
  <p>package com.example.lenovo.filterapp;</p>
  
  <pre><code>/**
   * Created by LENOVO on 2/6/2016.
   */
  public class Player {
  
      private  String name;
      private int img;
  
      public Player(String name, int img) {
          this.name = name;
          this.img  = img;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getImg() {
          return img;
      }
  
      public void setImg(int img) {
          this.img = img;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>activity_main.xml</p>
  </blockquote>
  
  <pre><code>        &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
  
              &gt;
              &lt;SearchView
  
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/searchView"
                  android:layout_alignParentTop="true"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentStart="true"
                  android:queryHint="search...." /&gt;
  
  
              &lt;ListView
  
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/listView"
                  android:layout_below="@+id/searchView"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentStart="true"
                  android:layout_marginTop="0dp" /&gt;
  
          &lt;/LinearLayout&gt;
  </code></pre>
  
  <blockquote>
    <p>manifest</p>
  </blockquote>
  
  <p></p>
  
  <pre><code>    &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name="com.example.lenovo.filterapp.MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.example.lenovo.filterapp.Lionel"
              android:label="@string/title_activity_lionel"
              android:theme="@style/AppTheme.NoActionBar" /&gt;
          &lt;activity
              android:name="com.example.lenovo.filterapp.Christiano"
              android:label="@string/title_activity_christiano"
              android:theme="@style/AppTheme.NoActionBar" /&gt;
          &lt;activity
              android:name="com.example.lenovo.filterapp.Neymar"
              android:label="@string/title_activity_neymar"
              android:theme="@style/AppTheme.NoActionBar"&gt;&lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>finding the reason behind my crash is really hard. What might be the problem? Thanks in advance</p>