java - NullPointer while using dynamic view in android -


i have created dynamic view repeats specific times. view has 2 textviews , 2 radio buttons default values. want change text values program getting nullpointer exception, here code:

    layoutinflater inflater = (layoutinflater)context.getsystemservice             (context.layout_inflater_service);     linearlayout scrollviewlinearlayout = (linearlayout)findviewbyid(r.id.parent); // layout inside scroll view     //int count=50;     for(int = 0; < studentlist.length; i++){         string data = studentlist[i];         string rollnum = data.split("--")[0];         string name = data.split("--")[1];          linearlayout layout2 = new linearlayout(context);         layout2.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.wrap_content));         view item = inflater.inflate(r.layout.item_layout, null, false);          layout2.addview(item);         layout2.setid(i);         textview trollnum = (textview)findviewbyid(r.id.rollnum);         trollnum.settext(rollnum);         textview tname = (textview)findviewbyid(r.id.name);         tname.settext(name);         scrollviewlinearlayout.addview(layout2);           log.d("id is: ", trollnum.gettext().tostring()); 

i getting nullpointer @ 'trollnum.settext(rollnum);'

how change text in view?

you trying find view in activity's layout doesn't exist instead of finding in layout inflated.

replace

textview trollnum = (textview)findviewbyid(r.id.rollnum); textview tname = (textview)findviewbyid(r.id.name); 

with

textview trollnum = (textview) item.findviewbyid(r.id.rollnum); textview tname = (textview) item.findviewbyid(r.id.name); 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -