NullPointerException in Opening Android Activity -
this question has answer here:
- what nullpointerexception, , how fix it? 12 answers
when cast elements other layout got error.
final spinner maining = (spinner) findviewbyid(r.id.spinner); final edittext sub1 = (edittext) findviewbyid(r.id.sub1); final edittext sub2 = (edittext) findviewbyid(r.id.sub2); final edittext sub3 = (edittext) findviewbyid(r.id.sub3); final edittext sub4 = (edittext) findviewbyid(r.id.sub4); final edittext sub5 = (edittext) findviewbyid(r.id.sub5); final edittext sub6 = (edittext) findviewbyid(r.id.sub6);
heres error
caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.view.view android.view.window.findviewbyid(int)' on null object reference
place code after setcontentview
in activity.
if want them available in every method of activity, declare them fields.
public class myactivity extends activity { spinner myspiner; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_layout); myspiner = (spinner) findviewbyid(r.id.myspiner);
and instantiate them after.
Comments
Post a Comment