java - Instantiating TextView in a nested class giving nullPointerException -


i attempting handle various button clicks though nested inner class implements onclicklistener. problem (more of wanting understand why is) comes concerning when must instantiate textview object. code below.

class buttonclick implements view.onclicklistener {     int id, textviewid;     private student student;     private textview textview;      public buttonclick(int buttonid, student student, int textviewid)     {         log.d(tag, "in buttonclick constructor" + integer.tostring(textviewid));         this.textviewid = textviewid;         this.id = buttonid;         this.student = student;         this.textview = (textview) view.findviewbyid(textviewid);           }         @override         public void onclick(view v) {             textview = (textview) view.findviewbyid(textviewid);             switch (id)             {                 case 0:                     log.d(tag, "in case 0: " + integer.tostring(textviewid));                     student.setparticipation(student.getparticipation()+1);                     textview.settext(integer.tostring(student.getparticipation()));                     break;         //more cases below, formatted same way. 

if textview instantiated in constructor , not in onclick method, throws nullpointerexception when trying textview.settext() in case 0. however, instantiating other things student object , this.id seem work fine , can use them normal in onclick method. if instantiate textview within onclick method, works fine, , can delete 1 in constructor. wondering why so.

thanks in advance,

-john


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -