When I click my button in emulator, my application crashes.
Below is my layout.xml:
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="40dp"
android:onClick="loginUser"
android:text="@string/login_text" />
Here is my method loginUser() in my MainActivity.java:
public void loginUser() {
Log.d("User Authentication Service", "Trying to login...");
doLogin(new Intent(getBaseContext(), LoginUserService.class));
}
I've defined which method should be called in my layout.xml using the below line:
android:onClick="loginUser"
But when I press the button in emulator, application crashes. I've tried changing the above value in layout.xml as show below:
android:onClick="loginUser()"
But nothing works. What's is wrong?