XML : Navigation Drawer whith ListView. Null Point Exception on ListView

i'm following this tutorial, for an Drawer Menu and a tab layout. So i have created the xml file for the menu, but i wouldn't use item but a ListView. Here is the xml code of the menu:

  <?xml version="1.0" encoding="utf-8"?>  <menu xmlns:android="http://schemas.android.com/apk/res/android">  <ListView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/listView"     android:layout_gravity="center" />  </menu>    

Here is the xml code of the activity:

  <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:fitsSystemWindows="true"  android:orientation="vertical">    <android.support.v7.widget.Toolbar      xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:background="@color/orange"      android:id="@+id/toolbar"      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"      app:title="Drawer With Swipe Tabs" />        <android.support.v4.widget.DrawerLayout      xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:app="http://schemas.android.com/apk/res-auto"      android:layout_height="match_parent"      android:layout_width="match_parent"      android:id="@+id/drawerLayout"      >        <FrameLayout          android:orientation="vertical"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:id="@+id/containerView">        </FrameLayout>            <android.support.design.widget.NavigationView          xmlns:android="http://schemas.android.com/apk/res/android"          xmlns:app="http://schemas.android.com/apk/res-auto"          android:layout_width="wrap_content"          android:layout_height="match_parent"          android:layout_gravity="start"          android:id="@+id/shitstuff"          app:itemTextColor="@color/black"          app:menu="@menu/drawermenu"          android:layout_marginTop="-24dp"          />    </android.support.v4.widget.DrawerLayout>    

And this is the MainActivity java code:

  public class MainActivity extends AppCompatActivity {  ArrayAdapter<Model> adapter;  List<Model> list = new ArrayList<>();    @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.activity_main);        ListView listView = (ListView)findViewById(R.id.listView);      adapter = new MyAdapter(this, getModel());      listView.setAdapter(adapter);    }    private List getModel() {      list.add(new Model("ISPEZIONE"));      return list;  }  }    

I have the null point exeption on the ListView. So i know because have the problem (I had the same problem with fragments) but i cant' resolve it with a menu. How can i do?

No comments:

Post a Comment