java - Android: Null Pointer Exception at Text View -


here code face exception

public class shosuper extends activity{  string officername; string arr[]; string[] offn; public void oncreate(bundle savedinstancestate) {     try{         super.oncreate(savedinstancestate);         final textview tv;         tv=(textview)findviewbyid(r.id.txt1);         system.out.println("i new activity");         arr=receiver.split(receiver.orignal, ",");          string value1= arr[1];         system.out.println("array index " + value1);         string value2=arr[2];         system.out.println("array 2nd index " + value2);         tv.settext(value1 + " @ " + value2);         officername= arr[5];         offn =new string[officername.length()];         offn=receiver.split(officername, "_");     }     catch(exception e){         e.printstacktrace();     }  setcontentview(r.layout.main);   } } 

on line tv.settext(value1 + " @ " + value2); face null pointer exception this

**04-12 13:25:18.105: warn/system.err(527): java.lang.nullpointerexception 04-12 13:25:18.265: warn/system.err(527):     @ com.sho.shosuper.oncreate(shosuper.java:24)** 

can me?

findviewbyid() finds view in current contentview, not random id in xml.

so when this:

tv=(textview)findviewbyid(r.id.txt1); 

it cannot find id, if available in layout.main: layout isn't set yet. call setcontentview(r.layout.main); before try , find views.

(you can use inflater 'random' view, , add view, doesn't seem looking for)


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -