android - Why app crashing? ListView with different views -


i try create listview settings page. first line edittext; 2-5 lines 2 texts.

so adapter class :

public class settingsadapter extends baseadapter {     private static final int type_name = 0;     private static final int type_setting = 1;     private static final int type_max_count = 2;      spmeditactionactivity   context;     layoutinflater          inflater;     arraylist               data;       settingsadapter(spmeditactionactivity _context) {          context = _context;         inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);          data = new arraylist();          for(int i=0;i<5;i++)             data.add("hello");     }        @override     public int getitemviewtype(int position) {         return position==0 ? type_name : type_setting;     }      @override     public int getviewtypecount() {         return type_max_count;     }      @override     public int getcount() {         return data.size();     }      @override     public object getitem(int position) {         return data.get(position);     }      @override     public long getitemid(int position) {         return position;     }       // пункт списка     @override     public view getview(int position, view convertview, viewgroup parent) {         int type = getitemviewtype(position);           view view = convertview;         if (view == null) {             if(type == type_name)                 view = inflater.inflate(r.layout.editactionactivity_settings_name, parent, false);             else                 view = inflater.inflate(r.layout.editactionactivity_setting, parent, false);          }         return view;     }  } 

activity:

public class spmeditactionactivity extends activity {       final int start_time_dialog = 1;     final int end_time_dialog = 2;  //==============ui===============================================     private listview        settings_listview ;      private settingsadapter settings_adapter;      private button save_button;     private button cancel_button; //==============================================================  //========ui listeners==========================================           private onclicklistener save_button_listener = new onclicklistener() {             public void onclick(view v) {                  save();             }         };               private onclicklistener cancel_button_listener = new onclicklistener() {             public void onclick(view v) {                  cancel();             }         };  //==============================================================  //==============================================================  //=================lifecycle methods============================     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_spmeditaction);            save_button  = (button) findviewbyid(r.id.editactionactivity_save_button);         cancel_button= (button) findviewbyid(r.id.editactionactivity_cancel_button);          settings_adapter = new settingsadapter(spmeditactionactivity.this);         settings_listview.setadapter(  settings_adapter    );           save_button.setonclicklistener(save_button_listener);         cancel_button.setonclicklistener(cancel_button_listener);       }  //==============================================================     private void save(){         finish();      }      private void cancel(){         finish();     }  } 

and in activity, when set adapter

settings_adapter = new settingsadapter(this); settings_listview.setadapter(  settings_adapter    ); 

my app crashing nullpointerexception .

can explain me, doing wrong?

ps. use tutorial

logcat output :

04-18 15:59:19.982: e/androidruntime(24150): fatal exception: main 04-18 15:59:19.982: e/androidruntime(24150): java.lang.runtimeexception: unable start activity componentinfo{com.hemul.soundprofilemanager/com.hemul.soundprofilemanager.spmeditactionactivity}: java.lang.nullpointerexception 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.activitythread.access$600(activitythread.java:130) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.os.handler.dispatchmessage(handler.java:99) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.os.looper.loop(looper.java:137) 04-18 15:59:19.982:e/androidruntime(24150):     @ android.app.activitythread.main(activitythread.java:4745) 04-18 15:59:19.982: e/androidruntime(24150):    @ java.lang.reflect.method.invokenative(native method) 04-18 15:59:19.982: e/androidruntime(24150):    @ java.lang.reflect.method.invoke(method.java:511) 04-18 15:59:19.982: e/androidruntime(24150):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 04-18 15:59:19.982: e/androidruntime(24150):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 04-18 15:59:19.982: e/androidruntime(24150):    @ dalvik.system.nativestart.main(native method) 04-18 15:59:19.982: e/androidruntime(24150): caused by: java.lang.nullpointerexception 04-18 15:59:19.982: e/androidruntime(24150):    @ com.hemul.soundprofilemanager.spmeditactionactivity.oncreate(spmeditactionactivity.java:111) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.activity.performcreate(activity.java:5008) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 04-18 15:59:19.982: e/androidruntime(24150):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 04-18 15:59:19.982: e/androidruntime(24150):    ... 11 more 

your settings_listview null, because haven't assigned reference in oncreate

get listview reference xml this

settings_listview=(listview)findviewbyid(r.id.yourlistview);  <-- listview id in xml 

after setcontentview(r.layout.activity_spmeditaction);


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -