title: onItemClickListener() crashes application
body: <p>I want to tap on an entry on the listview on my Activity_main to view the details on Activity_View.</p>
  
  <p>When I do so my application crashes.</p>
  
  <p>Where is my coding wrong?</p>
  
  <blockquote>
    <p>Activity_Main.xml</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;
  
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:weightSum="1"&gt;
  
      &lt;LinearLayout
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="71dp"
          android:layout_weight="0.35"&gt;
  
          &lt;LinearLayout
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:weightSum="1"
              android:focusableInTouchMode="true"&gt;
  
              &lt;EditText
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/txtSearch"
                  android:layout_weight="0.98"
                  android:hint="Search..." /&gt;
  
              &lt;Button
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Search"
                  android:id="@+id/btnSearch" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:weightSum="1"&gt;
  
              &lt;Button
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Sort By Date"
                  android:id="@+id/btnSortDate"
                  android:layout_gravity="left"
                  android:layout_weight="0.90" /&gt;
  
              &lt;Button
                  android:layout_width="174dp"
                  android:layout_height="wrap_content"
                  android:text="Sorty By Title"
                  android:id="@+id/btnSortTitle"
                  android:layout_gravity="right" /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;ListView
          android:layout_width="wrap_content"
          android:layout_height="252dp"
          android:id="@+id/listView"
          android:layout_weight="0.56" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Create Entry"
          android:id="@+id/btnNewEntry"
          android:layout_gravity="center_horizontal"
          android:layout_marginTop="10dp" /&gt;
  
    &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <blockquote>
    <p>MainActivity.Java</p>
  </blockquote>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private static final int REQUEST_CODE = 100;
  
  private static List&lt;Entry&gt; entryList;
  
  private ListView lvEntries;
  private EntryListAdaptor EntryListadapter;
  DatabaseHandler dbHandler;
  Uri imageUri = Uri.parse("android.resource://unipersonalinc.mypersonalediary/drawable/download.jpg");
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Button newBtn = (Button) findViewById(R.id.btnNewEntry);
      lvEntries = (ListView) findViewById(R.id.listView);
      dbHandler = new DatabaseHandler(getApplicationContext());
  
      entryList = new ArrayList&lt;&gt;();
      EntryListadapter = new EntryListAdaptor();
      lvEntries.setAdapter(EntryListadapter);
  
      newBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivityForResult(new Intent(MainActivity.this, Activity_Write.class), REQUEST_CODE);
          }
      });
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == Activity.RESULT_OK) {
          switch (requestCode) {
              case REQUEST_CODE:
                  if (data != null) {
                      int id = dbHandler.getEntriesCount();
                      long time = System.currentTimeMillis();
                      SimpleDateFormat dayTime = new SimpleDateFormat("dd-MM-yyyy mm:ss");
                      String date = dayTime.format(new Date(time));
                      String title = data.getStringExtra("Title");
                      String passage = data.getStringExtra("Passage");
                      Entry newEntry = new Entry(id, title, passage, imageUri, date);
                      entryList.add(newEntry);
                      dbHandler.createEntry(newEntry);
                      EntryListadapter.notifyDataSetChanged();
                  }
                  break;
          }
      }
      lvEntries.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              int searchId = position - 1;
              Cursor cursor = dbHandler.getData(searchId);
              String entryTitle = cursor.getString(cursor.getColumnIndex(dbHandler.KEY_TITLE));
              String entryPassage = cursor.getString(cursor.getColumnIndex(dbHandler.KEY_PASSAGE));
              String entryDate = cursor.getString(cursor.getColumnIndex(dbHandler.KEY_DATE));
  
              Bundle dataBundle = new Bundle();
              dataBundle.putString("title", entryTitle);
              dataBundle.putString("passage", entryPassage);
              dataBundle.putString("date", entryDate);
  
              Intent intent = new Intent(getApplicationContext(), Activity_View.class);
              intent.putExtras(dataBundle);
              startActivity(intent);
          }
      });
  }
  
  
  private class EntryListAdaptor extends ArrayAdapter&lt;Entry&gt; {
  
      private TextView tvTitle, tvDate;
  
      public EntryListAdaptor() {
          super(MainActivity.this, R.layout.listview_item, entryList);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          if (convertView == null)
              convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.listview_item, null);
  
          tvTitle = (TextView) convertView.findViewById(R.id.entryTitle);
          tvDate = (TextView) convertView.findViewById(R.id.entryDate);
  
          tvTitle.setText(entryList.get(position).getTitle());
          tvDate.setText(entryList.get(position).getDate());
          return convertView;
      }
    }
  }
  </code></pre>
  
  <blockquote>
    <p>activity_view.xml</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:weightSum="1"&gt;
  
      &lt;ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/ivImage"
          android:layout_gravity="center"
          android:src="@drawable/download" /&gt;
  
      &lt;TextView
          android:layout_width="367dp"
          android:layout_height="wrap_content"
          android:text="Testing"
          android:id="@+id/lblTitle"
          android:layout_marginTop="10dp"
          android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" /&gt;
  
      &lt;TextView
          android:layout_width="fill_parent"
          android:layout_height="222dp"
          android:text="this is solely for the storyboard and may not be the     final interface of the application"
          android:id="@+id/lblPassage"
          android:layout_marginTop="10dp"
          android:layout_weight="0.82" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="1/1/15"
          android:id="@+id/lblDate2"
          android:layout_gravity="right" /&gt;
  
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;Button
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:text="Edit"
              android:id="@+id/btnEdit"
              android:layout_marginTop="10dp"
              android:layout_gravity="left" /&gt;
  
          &lt;Button
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:text="Back"
              android:id="@+id/btnBack"
              android:layout_gravity="right"
              android:layout_marginTop="10dp" /&gt;
      &lt;/LinearLayout&gt;
  
    &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <blockquote>
    <p>Activity_View.Java</p>
  </blockquote>
  
  <pre><code>public class Activity_View extends AppCompatActivity {
  
  Button BackBtn = (Button) findViewById(R.id.btnBack);
  Button EditBtn = (Button) findViewById(R.id.btnEdit);
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.setContentView(R.layout.activity_view);
  
      Bundle extras = getIntent().getExtras();
      String entryTitle = extras.getString("title");
      TextView title = (TextView) findViewById(R.id.lblTitle);
      title.setText(entryTitle);
      String entryPassage = extras.getString("passage");
      TextView passage = (TextView) findViewById(R.id.lblPassage);
      passage.setText(entryPassage);
      String entryDate = extras.getString("date");
      TextView date = (TextView) findViewById(R.id.lblDate2);
      date.setText(entryDate);
  
      BackBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              finish();
          }
      });
    }
  }
  </code></pre>
  
  <blockquote>
    <p>Entry.Java</p>
  </blockquote>
  
  <pre><code>public class Entry {
  
  public String _title, _passage;
  public Uri _imageUri;
  public String _date;
  public int _id;
  
  public Entry (int id, String title, String passage, Uri imageUri, String date) {
      _id = id;
      _title = title;
      _passage = passage;
      _imageUri = imageUri;
      _date = date;
  }
  
  public int getId() { return _id; }
  public String getTitle() {
      return _title;
  }
  public String getPassage() { return _passage; }
  public Uri getImageUri() { return  _imageUri; }
  public String getDate() { return _date; }
  }
  </code></pre>
  
  <blockquote>
    <p>DatabaseHandler.Java</p>
  </blockquote>
  
  <pre><code>public class DatabaseHandler extends SQLiteOpenHelper {
  
  private static final int DATABASE_VERSION = 1;
  
  public static final String DATABASE_NAME = "entriesManager",
  TABLE_ENTRIES = "entries",
  KEY_ID = "id",
  KEY_TITLE = "title",
  KEY_PASSAGE = "passage",
  KEY_IMAGEURI = "imageUri",
  KEY_DATE="date";
  
  
  public DatabaseHandler(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE " + TABLE_ENTRIES + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_TITLE + " TEXT," + KEY_PASSAGE + " TEXT," + KEY_IMAGEURI + " TEXT" + KEY_DATE + "TEXT)");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_ENTRIES);
  
      onCreate(db);
  }
  
  public void createEntry(Entry entry) {
      SQLiteDatabase db = getWritableDatabase();
  
      ContentValues values = new ContentValues();
  
  
      values.put(KEY_ID,entry.getId());
      values.put(KEY_TITLE, entry.getTitle());
      values.put(KEY_PASSAGE, entry.getPassage());
      values.put(KEY_IMAGEURI, entry.getImageUri().toString());
  
      db.insert(TABLE_ENTRIES, null, values);
      db.close();
  }
  
  public Entry getEntry(int id) {
      SQLiteDatabase db = getReadableDatabase();
      Cursor cursor = db.query(TABLE_ENTRIES, new String[] {KEY_ID, KEY_TITLE, KEY_PASSAGE, KEY_IMAGEURI}, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null);
  
      if (cursor != null)
          cursor.moveToFirst();
  
      Entry entry = new Entry(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), Uri.parse(cursor.getString(3)), cursor.getString(4));
      db.close();
      cursor.close();
      return entry;
  }
  
  public void deleteEntry(Entry entry) {
      SQLiteDatabase db = getWritableDatabase();
      db.delete(TABLE_ENTRIES, KEY_ID + "=?", new String[]{String.valueOf(entry.getId())});
      db.close();
  }
  
  public int getEntriesCount() {
      SQLiteDatabase db;
  
      db = getReadableDatabase();
      Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_ENTRIES, null);
      int count = cursor.getCount();
      db.close();
      cursor.close();
  
      return count;
  }
  
  public int updataEntry(Entry entry) {
      SQLiteDatabase db = getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_TITLE, entry.getTitle());
      values.put(KEY_PASSAGE, entry.getPassage());
      values.put(KEY_IMAGEURI, entry.getImageUri().toString());
  
      return db.update(TABLE_ENTRIES, values, KEY_ID + "=?", new String[]{String.valueOf(entry.getId())});
  }
  
  public List&lt;Entry&gt; getAllEntries() {
      List&lt;Entry&gt; entries = new ArrayList&lt;Entry&gt;();
  
      SQLiteDatabase db = getWritableDatabase();
      Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_ENTRIES, null);
  
      if (cursor.moveToFirst()) {
          do {
              Entry entry = new Entry(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), Uri.parse(cursor.getString(3)), cursor.getString(4));
              entries.add(entry);
          }
          while (cursor.moveToNext());
      }
      return entries;
  }
  
  public Cursor getData(int id) {
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor res = db.rawQuery("select * from Entries where KEY_ID = " + id, null);
      res.moveToFirst();
      return res;
   }
  }
  </code></pre>
  
  <blockquote>
    <p>LogCat</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime: Process: unipersonalinc.mypersonalediary, PID: 5811
    12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{unipersonalinc.mypersonalediary/unipersonalinc.mypersonalediary.Activity_View}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.Activity.findViewById(Activity.java:2090)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at unipersonalinc.mypersonalediary.Activity_View.(Activity_View.java:17)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at java.lang.Class.newInstance(Native Method)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.Instrumentation.newActivity(Instrumentation.java:1067)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) </p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java) </p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) </p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) </p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
    12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) </p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)</p>
    
    <p>12-09 06:16:55.140 5811-5811/unipersonalinc.mypersonalediary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) </p>
  </blockquote>