Can't use button in android -


hi have been trying use onclicklistener on button give me error. code using:

public class login extends appcompatactivity {      private loginbutton loginbutton;     private callbackmanager callbackmanager;     private button testbutton;         @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         testbutton = (button) findviewbyid(r.id.login_activity_button);          testbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {              }         }); 

and error getting:

java.lang.runtimeexception: unable start activity componentinfo{com.buddifyapp.buddify.buddify/com.buddifyapp.buddify.buddify.ui.login}: java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.button.setonclicklistener(android.view.view$onclicklistener)' on null object reference

what doing wrong here ?

you have call setcontentview first, otherwise can't find views in layout.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     /* add below */     setcontentview(r.layout.my_layout);     testbutton = (button) findviewbyid(r.id.login_activity_button);      testbutton.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {          }     }); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -