android - Force close error -


what force close problem of program?

public class myactivity extends activity {      textview t=(textview)findviewbyid(r.id.textview1);      button r=(button)findviewbyid(r.id.button2);       private onclicklistener i=new onclicklistener(){          @override         public void onclick(view arg0) {             // todo auto-generated method stub             t.settext("fghffghfhgf");         }            };      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         r.setonclicklistener(i);     } } 

you need textview , button after inflating layout.

public class myactivity extends activity {      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         //here inflate layout         setcontentview(r.layout.main);          //now can widgets         final textview t= (textview)findviewbyid(r.id.textview1);         button r=(button)findviewbyid(r.id.button2);         r.setonclicklistener(new onclicklistener(){          @override         public void onclick(view arg0) {             // todo auto-generated method stub             t.settext("fghffghfhgf");             }        };       );     } } 

i recommend check this build first app.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -