java - I want to put selected ,custom arrayList items to same type another ArrayList. I did it as follows, But it gives NullPoint exception -
this code. want select/filter array list items in arraylist todolist. after want add selected items todolistcustom arraylist. did follows. gives null point exception. todolist array not null. contain values
/** * created kasunka on 4/13/2015. */ public class landingactivity extends activity implements view.onclicklistener{ private string filterkey; static arraylist<fields> todolist = null; static arraylist<fields> todolistcustom = null; hyperorder=10, partialorder=4; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_landing); initialize(); //initialize layout todoobject asytask = new todoobject(); // run asyn task , retrieve custom arralylist object. asytask.execute();// string url here. try { todolist = asytask.get(); arraylist<fiels> asyn task } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } todoobjectcount todoobjectcount = new todoobjectcount(todolist); try { typecount = todoobjectcount.objectcount(); } catch (executionexception e) { e.printstacktrace(); } catch (interruptedexception e) { e.printstacktrace(); } todo.settext("to "+typecount[0]); red.settext("late\n"+lateorders); green.settext(integer.tostring(greenorder)); yellow.settext(integer.tostring(yelloworders)); hyper.settext("hyp\n"+typecount[1]); partial.settext("pat\n"+partialorder); } private void initialize() { todo = (button)findviewbyid(r.id.blall); red = (button)findviewbyid(r.id.blred); green = (button)findviewbyid(r.id.blgreen); yellow = (button)findviewbyid(r.id.blyellow); hyper = (button)findviewbyid(r.id.blhyper); partial = (button)findviewbyid(r.id.blpartil); details = (button)findviewbyid(r.id.bldetails); todo.setonclicklistener(this); yellow.setonclicklistener(this); hyper.setonclicklistener(this); } @override public void onclick(view v) { switch(v.getid()){ case r.id.blall:{ filterkey = "all"; // pass filter intent todolistactivity = new intent("android.intent.action.todoactivity"); bundle bundleobject = new bundle(); // create bundle , put bundle in bundleobject.putserializable("key", todolist); todolistactivity.putextras(bundleobject); // put bundle in intent startactivity(todolistactivity); }break; case r.id.blred:{ filterkey="red"; // pass filter setcustomlist(filterkey); }break; case r.id.blyellow:{ filterkey="yellow"; }break; case r.id.blgreen:{ filterkey="green"; }break; case r.id.blhyper:{ filterkey="hyper"; setcustomlist(filterkey); }break; case r.id.blpartil:{ filterkey="partial"; }break; case r.id.bldetails:{ filterkey="details"; } } } private void setcustomlist(string filterkey) { switch (filterkey){ case "red":{ }break; case "yellow":{ }break; case "green":{ }break; case "hyper":{ (int i=0; i<todolist.size();i++){ if(todolist.get(i).getishyper().contains("0")){ todolistcustom.add(todolist.get(i)); <-- error here null point exception } starttodoactivity(); } }break; case "partial":{ }break; } } private void starttodoactivity() { intent todolistactivity = new intent("android.intent.action.todoactivity"); bundle bundleobject = new bundle(); // create bundle , put bundle in bundleobject.putserializable("key", todolistcustom); todolistactivity.putextras(bundleobject); // put bundle in intent startactivity(todolistactivity); } }
asyn task excute , return arraylist , not null.
you need instantiate todolistcustom
:
static arraylist<fields> todolistcustom = new arraylist<>();