Skip to content
Advertisement

My android studio app crashes when I touch the screen

My app keeps crashing on the mainActivity screen everytime I touch empty space on the screen. I have three buttons, two radioButtons, a textview, and two editText fields; whenever I touch these my app works fine, but if I ever touch white space, then the whole app crashes. I have minSDk of 15 and targetSDK of 23. I am adding Users to a database using SQLiteOpenHelper. Users have a name, password, and type (buyer or seller). Here is my code:

MainActivity.java

JavaScript

activity_main.xml

JavaScript

AndroidManifest.xml

JavaScript

Can anyone tell me why this happens. Thanks in advance for the help!

Advertisement

Answer

Using in your layout the attribute

JavaScript

you have to implement inside your Activity a method with the same name

JavaScript

The View passed into the method is a reference to the widget that was clicked.

When a user clicks the view, the Android system calls the activity’s clear(View) method.

Pay attention: if you are using a fragment, Android will not look for the onClick method in the fragment but only in the current Activity.

You can achieve the same using:

JavaScript
Advertisement