Home > front end >  Can someone help me to fix this
Can someone help me to fix this

Time:03-31

In AIDE it says no error, but when im trying to install the apk it says

Unable to start activity ComponentInfo{com.mytrippin.myclix/com.mytrippin.myclix.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference

Here what im done

MainActivity.java

MAIN.xml

CodePudding user response:

The on click listener is implemented wrongly. You're missing the new View.onCLickListener.

Here is an example.

 button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // your handler code here
             }
         });

CodePudding user response:

You can use lambda's function simpler approach

button.setOnClickListener(v -> {
    //Your Listener Code Here
});

  • Related