title: NullPointerException on a new activity
body: <p>This is the class in which I implemented <code>onItemClickListener</code> and am starting the new activity. According to the logcat, the <code>NullPointerException</code> is happening while I am starting <code>GetAppoint</code>.</p>
  
  <pre><code> public class Sdoctors extends Fragment implements OnItemSelectedListener {
      public String itemselect = "";
      public doctorsDBadapter dbhelper;
      public SimpleCursorAdapter dataAdapter;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          View rootView = inflater.inflate(R.layout.sdoctors, container, false);
          Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner1);
          spinner.setOnItemSelectedListener(this);
          List&lt;String&gt; categories = new ArrayList&lt;String&gt;();
          categories.add("By Name");
          categories.add("By Speciality");
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(),
                  android.R.layout.simple_spinner_item, categories);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(adapter);
          dbhelper = new doctorsDBadapter(getActivity());
          dbhelper.open();
          dbhelper.deletealldoctors();
          dbhelper.insertsomedoctors();
          final Cursor cursor = dbhelper.fetchalldoctors();
  
          String[] columns = new String[] { doctorsDBadapter.KEYNAME,
                  doctorsDBadapter.KEYSPEC, doctorsDBadapter.KEYTIME };
  
          int[] to = new int[] { R.id.name, R.id.speac, R.id.time };
  
          dataAdapter = new SimpleCursorAdapter(getActivity(),
                  R.layout.doctorsinfo, cursor, columns, to, 0);
  
          final ListView listview = (ListView) rootView
                  .findViewById(R.id.dlistView1);
          listview.setAdapter(dataAdapter);
  
          listview.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
                  // TODO Auto-generated method stub
  
                  Cursor cursor = (Cursor) listview.getItemAtPosition(position);
  
                  String doctor = cursor.getString(cursor
                          .getColumnIndexOrThrow("_name"));
  
                  String spec = cursor.getString(cursor
                          .getColumnIndexOrThrow("_specialist"));
  
                  String time = cursor.getString(cursor
                          .getColumnIndexOrThrow("_time"));
                  Log.i("DOCTOR", doctor);
                  Log.i("SPECIALIST", spec);
                  Log.i("TIME",time);
                  Intent openApp = new Intent(view.getContext(), GetAppoint.class);
                  openApp.putExtra("doct", doctor);
                  openApp.putExtra("specs", spec);
                  openApp.putExtra("times", time);
                  startActivity(openApp);
              }
          });
  
          EditText myfilter = (EditText) rootView.findViewById(R.id.editText1);
  
          myfilter.addTextChangedListener(new TextWatcher() {
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before,
                      int count) {
                  // TODO Auto-generated method stub
                  dataAdapter.getFilter().filter(s.toString());
              }
  
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void afterTextChanged(Editable s) {
                  // TODO Auto-generated method stub
  
              }
          });
  
          dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
  
              @Override
              public Cursor runQuery(CharSequence constraint) {
                  // TODO Auto-generated method stub
                  if (itemselect == "By Speciality") {
                      return dbhelper.fetchdoctorsbyspec(constraint.toString());
                  } else if (itemselect == "By Name") {
                      return dbhelper.fetchdoctorsbyname(constraint.toString());
                  }
                  return cursor;
              }
          });
          return rootView;
  
      }
  
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position,
              long id) {
          // TODO Auto-generated method stub
          itemselect = parent.getItemAtPosition(position).toString();
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
          // TODO Auto-generated method stub
  
      }}
  </code></pre>
  
  <p>And this is the new activity class GetAppoint.java</p>
  
  <pre><code>public class GetAppoint extends Activity{
  
  ActionBar actiobar;
  TextView name,spec,time;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.getappoint);
  
      name = (TextView) findViewById(R.id.textView2);
      spec = (TextView) findViewById(R.id.textview4);
      time = (TextView) findViewById(R.id.textView5);
  
      actiobar = getActionBar();
      actiobar.setHomeButtonEnabled(true);
      actiobar.setDisplayHomeAsUpEnabled(true);
  
      String doc = getIntent().getExtras().getString("doct");
      String specialist = getIntent().getExtras().getString("specs");
      String doctime = getIntent().getExtras().getString("times");
  
      name.append(doc);
      spec.append(specialist);
      time.append(doctime);
  
  
  }}
  </code></pre>
  
  <p>This is the xml file getappoint.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="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;DatePicker
          android:id="@+id/datePicker1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView7" /&gt;
  
      &lt;TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/textView1"
          android:layout_marginTop="14dp"
          android:layout_toLeftOf="@+id/textView7"
          android:text="Specialist"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/textView4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/textView3"
          android:layout_alignBottom="@+id/textView3"
          android:layout_alignLeft="@+id/textView5"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/textView3"
          android:layout_alignLeft="@+id/textView4"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;TextView
          android:id="@+id/textView6"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/textView5"
          android:layout_alignBottom="@+id/textView5"
          android:layout_alignRight="@+id/textView3"
          android:text="Time"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_marginTop="20dp"
          android:layout_toLeftOf="@+id/textView5"
          android:text="Name"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/textView5"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/textView7"
          android:layout_below="@+id/textView4"
          android:layout_marginLeft="26dp"
          android:layout_marginTop="14dp"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;TextView
          android:id="@+id/textView7"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/textView6"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="18dp"
          android:text="Select Date"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
      &lt;Button
          android:id="@+id/appointbut"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/datePicker1"
          android:text="Confirm" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is my Logcat</p>
  
  <pre><code>03-07 00:22:53.770: E/AndroidRuntime(10342): FATAL EXCEPTION: main
  03-07 00:22:53.770: E/AndroidRuntime(10342): Process: com.beproject.pocketdoctor, PID: 10342
  03-07 00:22:53.770: E/AndroidRuntime(10342): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.beproject.pocketdoctor/com.beproject.pocketdoctor.GetAppoint}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.append(java.lang.CharSequence)' on a null object reference
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.ActivityThread.access$800(ActivityThread.java:148)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.os.Handler.dispatchMessage(Handler.java:102)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.os.Looper.loop(Looper.java:135)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.ActivityThread.main(ActivityThread.java:5312)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at java.lang.reflect.Method.invoke(Native Method)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at java.lang.reflect.Method.invoke(Method.java:372)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
  03-07 00:22:53.770: E/AndroidRuntime(10342): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.append(java.lang.CharSequence)' on a null object reference
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at com.beproject.pocketdoctor.GetAppoint.onCreate(GetAppoint.java:31)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.Activity.performCreate(Activity.java:5953)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
  03-07 00:22:53.770: E/AndroidRuntime(10342):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
  </code></pre>