title: Moving to another activity by clicking ImageView
body: <p>I want to move to other activity by clicking photo profile, I don't know how to do it. It always give me an error when I defined it. I want to move to another activity using id in <code>string-array</code> names see <strong>list_tutor.xml</strong> and <strong>strings.xml</strong>.</p>
  
  <pre><code>a = (ImageView)findViewById(R.id.list_tutor);
  </code></pre>
  
  <p>If I write that code has no error, but app crashed and stop working:</p>
  
  <pre><code>11-30 05:57:30.787 7171-7171/com.example.abdullahalhajri.smarttutor D/AndroidRuntime: Shutting down VM
  11-30 05:57:30.790 7171-7171/com.example.abdullahalhajri.smarttutor E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.abdullahalhajri.smarttutor, PID: 7171
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abdullahalhajri.smarttutor/com.example.abdullahalhajri.smarttutor.activities.SearchRating}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
        at com.example.abdullahalhajri.smarttutor.activities.SearchRating.onCreate(SearchRating.java:63)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Activity.performCreate(Activity.java:6991)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  </code></pre>
  
  <p>If I write that</p>
  
  <pre><code>a = (ImageView)findViewById(R.id.khalid)
  </code></pre>
  
  <p>(khalid is item on profile_pics items see strings.xml), it gives me red color error on <code>khalid</code>: </p>
  
  <blockquote>
    <p>cannot resolve symbol "khalid"</p>
  </blockquote>
  
  <p><strong>main activity</strong>                                                                                               </p>
  
  <pre><code>public class SearchRating extends Activity implements OnItemClickListener {
      ImageView a;
      String[] member_names;
      TypedArray profile_pics;
      String[] statues;
      String[] contactType;
  
      List&lt;RowItem&gt; rowItems;
      ListView mylistview;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.list_tutor);
          Intent intent0 = getIntent();
  
           a = (ImageView)findViewById(R.id.profile_pic);;
          a.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view1) {
                 Intent myIntent = new Intent(SearchRating.this, TutorProfile.class);
              startActivity(myIntent);
                                   }
                               });
          rowItems = new ArrayList&lt;RowItem&gt;();
  
          member_names = getResources().getStringArray(R.array.Member_names);
  
          profile_pics = getResources().obtainTypedArray(R.array.profile_pics);
  
          statues = getResources().getStringArray(R.array.statues);
  
          contactType = getResources().getStringArray(R.array.contactType);
  
          for (int i = 0; i &lt; member_names.length; i++) {
              RowItem item = new RowItem(member_names[i],
                      profile_pics.getResourceId(i, -1), statues[i],
                      contactType[i]);
              rowItems.add(item);
          }
  
          mylistview = (ListView) findViewById(R.id.list);
          CustomAdapter adapter = new CustomAdapter(this, rowItems);
          mylistview.setAdapter(adapter);
  
          mylistview.setOnItemClickListener(this);
  
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,
                              long id) {
  
          String member_name = rowItems.get(position).getMember_name();
          Toast.makeText(getApplicationContext(), "" + member_name,
                  Toast.LENGTH_SHORT).show();
      }
  
  }                                                                          
  </code></pre>
  
  <p><strong>CustomAdapter</strong></p>
  
  <pre><code>package com.example.abdullahalhajri.smarttutor.activities;
  
  /**
   * Created by Khalid on 11/27/17.
   */
  
  
  import android.app.Activity;
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  import com.example.abdullahalhajri.smarttutor.R;
  import java.util.List;
  
  public class CustomAdapter extends BaseAdapter {
  
      Context context;
      List&lt;RowItem&gt; rowItems;
  
      CustomAdapter(Context context, List&lt;RowItem&gt; rowItems) {
          this.context = context;
          this.rowItems = rowItems;
      }
  
      @Override
      public int getCount() {
          return rowItems.size();
      }
  
      @Override
      public Object getItem(int position) {
          return rowItems.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return rowItems.indexOf(getItem(position));
      }
  
      /* private view holder class */
      private class ViewHolder {
          ImageView profile_pic;
          TextView member_name;
          TextView status;
          TextView contactType;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          ViewHolder holder = null;
  
          LayoutInflater mInflater = (LayoutInflater) context
                  .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
          if (convertView == null) {
              convertView = mInflater.inflate(R.layout.list_tutor, null);
              holder = new ViewHolder();
  
              holder.member_name = (TextView) convertView
                      .findViewById(R.id.member_name);
              holder.profile_pic = (ImageView) convertView
                      .findViewById(R.id.profile_pic);
              holder.status = (TextView) convertView.findViewById(R.id.status);
              holder.contactType = (TextView) convertView
                      .findViewById(R.id.contact_type);
  
              RowItem row_pos = rowItems.get(position);
  
              holder.profile_pic.setImageResource(row_pos.getProfile_pic_id());
              holder.member_name.setText(row_pos.getMember_name());
              holder.status.setText(row_pos.getStatus());
              holder.contactType.setText(row_pos.getContactType());
  
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          return convertView;
      }
  
  }
  </code></pre>
  
  <p><strong>TutorProfile</strong></p>
  
  <pre><code>package com.example.abdullahalhajri.smarttutor.activities;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  
  import com.example.abdullahalhajri.smarttutor.R;
  
  public class TutorProfile extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_tutorprofile);
          Intent intent0 = getIntent();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>list_tutor.xml</p>
  
  <pre><code>        &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="2dp" &gt;
  
      &lt;ImageView
          android:id="@+id/profile_pic"
          android:layout_width="70dp"
          android:layout_height="70dp"
          android:contentDescription="desc"
          android:paddingLeft="10dp"
          android:paddingRight="10dp" /&gt;
  
      &lt;TextView
          android:id="@+id/member_name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp"
          android:layout_toRightOf="@+id/profile_pic"
          android:paddingBottom="10dp"
          android:text="txt"
          android:textSize="20sp" /&gt;
  
      &lt;TextView
          android:id="@+id/status"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/member_name"
          android:layout_below="@+id/member_name"
          android:text="txt"
          android:textSize="16sp" /&gt;
  
      &lt;TextView
          android:id="@+id/contact_type"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/member_name"
          android:layout_alignBottom="@+id/member_name"
          android:layout_alignParentRight="true"
          android:text="txt"
          android:textSize="16sp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>strings.xml</strong></p>
  
  <pre><code>  &lt;!-- ListviewTuruor --&gt;
      &lt;string name="action_settings"&gt;Settings&lt;/string&gt;
      &lt;string name="hello_world"&gt;Hello world!&lt;/string&gt;
      &lt;!-- Names --&gt;
      &lt;string-array name="Member_names"&gt;
  
          &lt;item&gt;Robert&lt;/item&gt;
          &lt;item&gt;Shanni&lt;/item&gt;
          &lt;item&gt;Rachael&lt;/item&gt;
          &lt;item&gt;Maddy&lt;/item&gt;
          &lt;item&gt;Kate&lt;/item&gt;
          &lt;item&gt;Emma&lt;/item&gt;
          &lt;item&gt;Isabella&lt;/item&gt;
          &lt;item&gt;Khalid&lt;/item&gt;
          &lt;item&gt;Sophia&lt;/item&gt;
      &lt;/string-array&gt;
  
      &lt;!-- Pictures --&gt;
      &lt;array name="profile_pics"&gt;
          &lt;item&gt;@drawable/robert&lt;/item&gt;
          &lt;item&gt;@drawable/shanni&lt;/item&gt;
          &lt;item&gt;@drawable/rachael&lt;/item&gt;
          &lt;item&gt;@drawable/maddy_pic&lt;/item&gt;
          &lt;item&gt;@drawable/kate&lt;/item&gt;
          &lt;item&gt;@drawable/nikhil_pic&lt;/item&gt;
          &lt;item&gt;@drawable/isabella&lt;/item&gt;
          &lt;item&gt;@drawable/khalid&lt;/item&gt;
          &lt;item&gt;@drawable/sophia&lt;/item&gt;
      &lt;/array&gt;
  
      &lt;!-- Status --&gt;
      &lt;string-array name="statues"&gt;
          &lt;item&gt;Math&lt;/item&gt;
          &lt;item&gt;IT&lt;/item&gt;
          &lt;item&gt;Biology&lt;/item&gt;
          &lt;item&gt;English&lt;/item&gt;
          &lt;item&gt;Art&lt;/item&gt;
          &lt;item&gt;Natural Science&lt;/item&gt;
          &lt;item&gt;Art&lt;/item&gt;
          &lt;item&gt;Networking&lt;/item&gt;
          &lt;item&gt;Chemistry&lt;/item&gt;
      &lt;/string-array&gt;
  
      &lt;!-- contact type --&gt;
      &lt;string-array name="contactType"&gt;
          &lt;item&gt;4.7/5&lt;/item&gt;
          &lt;item&gt;4.6/5&lt;/item&gt;
          &lt;item&gt;4.4/5&lt;/item&gt;
          &lt;item&gt;4/5&lt;/item&gt;
          &lt;item&gt;3.9/5&lt;/item&gt;
          &lt;item&gt;3.5/5&lt;/item&gt;
          &lt;item&gt;3.5/5&lt;/item&gt;
          &lt;item&gt;2.7/5&lt;/item&gt;
          &lt;item&gt;2/5&lt;/item&gt;
      &lt;/string-array&gt;
  </code></pre>
  
  <p>layout <strong>activity_search_rating</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>