java - Why does my App crash? Drawer -


i have problem app doesn't start,it crashes. thankful help. :) tried use listview = (listview) findviewbyid(r.id.drawerlist);

but there no elements in drawer.

mainactivity.java:

package com.ce.de;   import android.app.activity; import android.os.bundle; import android.support.v4.widget.drawerlayout; import android.view.menu; import android.view.menuitem; import android.widget.arrayadapter; import android.widget.listview;  public class mainactivity extends activity {  private drawerlayout drawerlayout; private listview listview; private string[] planets; @override protected void oncreate(bundle savedinstancestate){       super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     drawerlayout=(drawerlayout) findviewbyid(r.id.drawerlayout);     planets=getresources().getstringarray(r.array.planets);       listview.setadapter(new arrayadapter<string>                              (this,android.r.layout.simple_list_item_1,planets));     }  } 

activity_main.xml

<android.support.v4.widget.drawerlayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/drawerlayout"    android:layout_width="match_parent"   android:layout_height="match_parent">     <framelayout      android:id="@+id/maincontent"     android:layout_width="match_parent"     android:layout_height="match_parent">     </framelayout>     <listview     android:id="@+id/drawerlist"     android:layout_width="240dp"     android:layout_height="match_parent"     android:layout_gravity="left">     </listview>     </android.support.v4.widget.drawerlayout> 

this issue have not initialized listview

solution

create new listview object -

@override protected void oncreate(bundle savedinstancestate){      ....      listview = (listview)findviewbyid(r.id.drawerlist);     listview.setadapter(...);      }  } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -