Skip to content Skip to sidebar Skip to footer

App Stops Working When I Call A Second Activity With Nav Drawer From Nav Drawer Click

Okay so I want to have the navigation drawer available to use from all activities. I am creating a soundboard app and when I click on item 0 on the list I want it to take me to the

Solution 1:

Your problem is with referring to the ListView in the DrawerLayout incorrectly in the MrsClubb activity. Here is an example of how you should be using and referring to the ListView.

<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">
    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <ListView
        android:id="@+id/drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#111"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

Now you can refer to the ListView in the DrawerLayout as:

ListViewlv= (ListView) findViewByid(R.id.drawer);

Using Android provided IDs can sometimes get tricky and I believe this is where you have gone wrong.

Solution 2:

Here is your problem:

 java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference

Looks like your listView is null, check to make sure you are declaring and finding it correctly in your activity.

Post a Comment for "App Stops Working When I Call A Second Activity With Nav Drawer From Nav Drawer Click"