I have a Navigation Drawer and want to retrieve the content inside the item in the ListView I am going to click. I can retrieve the position, but no way to link to the list view to get the content of the item clicked. in the debugger i see that is present a list view and indicate also the id left\_drawer that is the same I have into the xml file and I try to retrieve:

```
 android.widget.ListView{634ed4d VFED.VC.. .F..H.ID 0,0-630,1731 #7f0e004f app:id/left_drawer}

```

so I am wondering what I am doing wrong to have a NPE and why I don't retrieve the item

```
 @Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {

//I have the position of the list view, and want to retrieve the content of the selected item at that position
ListView listView = (ListView) view.findViewById(R.id.left_drawer);
 String sk = (String) listView.getItemAtPosition(position);//NPE because listView is null?
        Log.d("DEBUG", "onItemClick: "+sk);

//      listView.getChildAt(0);
//listView.getSelectedItem();

}
}

```

And this is the error message

```
  Process: android.com.myapp, PID: 28051 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.widget.ListView.getItemAtPosition(int)' on a null object reference
                                                                                at android.com.myapp.DrawerItemClickListener.onItemClick(DrawerItemClickListener.java:22)

```

this is Navigation Drawer

```
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"

    >
    <!-- The main content view -->

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment_as_list"
    android:name="android.com.myApp.FragmentA"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        />

    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"

        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="19dp"
        android:background="@drawable/image_background"
        android:paddingTop="?android:attr/actionBarSize"

        android:paddingLeft="@dimen/activity_horizontal_margin"

        android:paddingRight="@dimen/activity_horizontal_margin"

        android:paddingBottom="@dimen/activity_vertical_margin"
      />
</android.support.v4.widget.DrawerLayout>

```

---

Update
======

In my opinion this is not a trivial NPE question. Even if I try to set a condition to eliminate the Exception was unavoidable because ListView was initiated twice once in the Main Class another time in the new class where the Google tutorial moved the Drawer object anonymous class.

Also there is any case mentioned in SO on how to retrieve an item specifically from a [Navigation Drawer](https://developer.android.com/training/implementing-navigation/nav-drawer.html). Although the problem is intuitively resizable to a simple `ListView.getItemAtPosition()`. Putting back in one class everything is working.