我目前有SignupActivity和LoginActivity活动。两者都有相应的xml文件。两者都使用Firebase Auth,一个用于注册,一个用于登录。我的注册活动工作正常但是当我点击“登录”时登录活动上的按钮没有任何反应。我在OnClick开关语句中编写了调试消息,但它没有打印它们。这让我相信问题在于OnClickListener,但是代码与SignupActivity活动完全相同。
非常感谢任何帮助!
package com.mad.losesano;
import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class LoginActivity extends Activity implements View.OnClickListener {
private FirebaseAuth mAuth;
EditText et_email, et_password;
Button login_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
et_email = (EditText) findViewById(R.id.email_et_login);
et_password = (EditText) findViewById(R.id.password_et_login);
findViewById(R.id.register_tv).setOnClickListener(this);
login_button = (Button) findViewById(R.id.login_button);
login_button.setOnClickListener(this);
}
private void userLogin() {
String email = et_email.getText().toString().trim();
String password = et_password.getText().toString().trim();
if (email.isEmpty()) {
et_email.setError("Email is required");
et_email.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
et_email.setError("Please enter a valid email");
et_email.requestFocus();
return;
}
if (password.isEmpty()) {
et_password.setError("Password is required");
et_password.requestFocus();
return;
}
if (password.length() < 6) {
et_password.setError("Minimum lenght of password should be 6");
et_password.requestFocus();
return;
}
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
finish();
Intent intent = new Intent(LoginActivity.this, LoggedInActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
if (mAuth.getCurrentUser() != null) {
finish();
startActivity(new Intent(this, LoggedInActivity.class));
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.register_tv:
finish();
Log.d("LoSeSANO", "Register Button Clicked");
startActivity(new Intent(LoginActivity.this, SignupActivity.class));
break;
case R.id.login_button:
Log.d("LoSeSANO", "Login Button Clicked");
userLogin();
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_bg">
<TextView
android:id="@+id/welcome_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:fontFamily="sans-serif-light"
android:text="@string/welcome_string"
android:textColor="#f0eeec"
android:textSize="40dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="202dp"
android:layout_height="62dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/sub_welcome_string"
android:textColor="#f0eeec"
android:textSize="14dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/welcome_tv" />
<EditText
android:id="@+id/email_et_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:backgroundTint="@android:color/holo_green_light"
android:ems="10"
android:fontFamily="sans-serif-light"
android:inputType="textPersonName"
android:text="@string/register_et_string"
android:textColor="#f0eeec"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<EditText
android:id="@+id/password_et_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:backgroundTint="@android:color/holo_green_light"
android:ems="10"
android:fontFamily="sans-serif-light"
android:hint="Password"
android:inputType="textPassword"
android:text="Password"
android:textColor="#f0eeec"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/email_et_login" />
<Button
android:id="@+id/login_button"
android:layout_width="151dp"
android:layout_height="55dp"
android:layout_marginTop="16dp"
android:backgroundTint="#6c8c0e"
android:fontFamily="sans-serif-light"
android:text="@string/login_register_button_string"
android:textColor="#f0eeec"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password_et_login" />
<TextView
android:id="@+id/register_tv"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_marginTop="8dp"
android:backgroundTint="#6c8c0e"
android:fontFamily="sans-serif-light"
android:text="@string/register_tv_string"
android:textColor="#f0eeec"
android:textSize="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_button" />
<TextView
android:id="@+id/password_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#6c8c0e"
android:fontFamily="sans-serif-light"
android:text="@string/forgot_password_tv_string"
android:textColor="#f0eeec"
android:textSize="16dp"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/register_tv" />
</android.support.constraint.ConstraintLayout>
logcat的
03-16 17:35:45.988 10682-10682/? I/zygote: Not late-enabling -Xcheck:jni (already on)
03-16 17:35:46.010 10682-10682/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
03-16 17:35:46.201 10682-10682/com.mad.losesano W/zygote: Skipping duplicate class check due to unrecognized classloader
03-16 17:35:46.205 10682-10682/com.mad.losesano W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-16 17:35:46.228 10682-10682/com.mad.losesano W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-16 17:35:46.232 10682-10682/com.mad.losesano I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
03-16 17:35:46.246 10682-10702/com.mad.losesano W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-16 17:35:46.259 10682-10682/com.mad.losesano D/FirebaseAuth: Notifying id token listeners about user ( Xt1ezVbilKhnCJ6HP7Vbgez21wp1 ).
03-16 17:35:46.288 10682-10682/com.mad.losesano D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
03-16 17:35:46.299 10682-10702/com.mad.losesano I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
03-16 17:35:46.299 10682-10702/com.mad.losesano I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
03-16 17:35:46.317 10682-10682/com.mad.losesano V/FA: Cancelling job. JobID: -2059533557
03-16 17:35:46.320 10682-10682/com.mad.losesano V/FA: Registered activity lifecycle callback
03-16 17:35:46.321 10682-10682/com.mad.losesano I/FirebaseInitProvider: FirebaseApp initialization successful
03-16 17:35:46.346 10682-10707/com.mad.losesano V/FA: Collection enabled
03-16 17:35:46.347 10682-10707/com.mad.losesano V/FA: App package, google app id: com.mad.losesano, 1:789814958391:android:0c23a95a5789dfa5
03-16 17:35:46.349 10682-10707/com.mad.losesano I/FA: App measurement is starting up, version: 11910
03-16 17:35:46.349 10682-10707/com.mad.losesano I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-16 17:35:46.352 10682-10707/com.mad.losesano I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.mad.losesano
03-16 17:35:46.352 10682-10707/com.mad.losesano D/FA: Debug-level message logging enabled
03-16 17:35:46.358 10682-10682/com.mad.losesano V/FA: onActivityCreated
03-16 17:35:46.395 10682-10707/com.mad.losesano V/FA: Connecting to remote service
03-16 17:35:46.408 10682-10707/com.mad.losesano V/FA: Connection attempt already in progress
03-16 17:35:46.529 10682-10707/com.mad.losesano V/FA: Connection attempt already in progress
03-16 17:35:46.531 10682-10707/com.mad.losesano V/FA: Activity resumed, time: 10669475
03-16 17:35:46.539 10682-10707/com.mad.losesano I/FA: Tag Manager is not found and thus will not be used
03-16 17:35:46.540 10682-10707/com.mad.losesano D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=SignupActivity, firebase_screen_id(_si)=359863105737247052}]
03-16 17:35:46.552 10682-10709/com.mad.losesano D/OpenGLRenderer: HWUI GL Pipeline
03-16 17:35:46.571 10682-10682/com.mad.losesano D/FirebaseApp: Notifying auth state listeners.
03-16 17:35:46.572 10682-10682/com.mad.losesano D/FirebaseApp: Notified 0 auth state listeners.
03-16 17:35:46.614 10682-10707/com.mad.losesano V/FA: Connection attempt already in progress
03-16 17:35:46.646 10682-10709/com.mad.losesano I/OpenGLRenderer: Initialized EGL, version 1.4
03-16 17:35:46.647 10682-10709/com.mad.losesano D/OpenGLRenderer: Swap behavior 1
03-16 17:35:46.647 10682-10709/com.mad.losesano W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
03-16 17:35:46.647 10682-10709/com.mad.losesano D/OpenGLRenderer: Swap behavior 0
03-16 17:35:46.653 10682-10709/com.mad.losesano D/EGL_emulation: eglCreateContext: 0xa177dd40: maj 3 min 0 rcv 3
03-16 17:35:46.694 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:46.695 10682-10709/com.mad.losesano E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-16 17:35:46.695 10682-10709/com.mad.losesano E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
03-16 17:35:46.695 10682-10709/com.mad.losesano E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-16 17:35:46.695 10682-10709/com.mad.losesano E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
03-16 17:35:46.744 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:47.001 10682-10707/com.mad.losesano D/FA: Connected to remote service
03-16 17:35:47.002 10682-10707/com.mad.losesano V/FA: Processing queued up service tasks: 4
03-16 17:35:47.054 10682-10682/com.mad.losesano I/AssistStructure: Flattened final assist data: 2380 bytes, containing 1 windows, 7 views
03-16 17:35:48.232 10682-10682/com.mad.losesano I/AssistStructure: Flattened final assist data: 2584 bytes, containing 2 windows, 8 views
03-16 17:35:48.239 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.250 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.271 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.289 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.437 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.477 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.660 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.675 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:48.788 10682-10687/com.mad.losesano I/zygote: Do partial code cache collection, code=29KB, data=30KB
03-16 17:35:48.789 10682-10687/com.mad.losesano I/zygote: After code cache collection, code=29KB, data=30KB
03-16 17:35:48.789 10682-10687/com.mad.losesano I/zygote: Increasing code cache capacity to 128KB
03-16 17:35:48.890 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:49.016 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:49.033 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:49.911 10682-10687/com.mad.losesano I/zygote: Do partial code cache collection, code=58KB, data=58KB
03-16 17:35:49.913 10682-10687/com.mad.losesano I/zygote: After code cache collection, code=58KB, data=58KB
03-16 17:35:49.913 10682-10687/com.mad.losesano I/zygote: Increasing code cache capacity to 256KB
03-16 17:35:49.985 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:35:49.985 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:35:50.164 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:35:50.164 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:35:50.208 10682-10687/com.mad.losesano I/zygote: Do full code cache collection, code=115KB, data=115KB
03-16 17:35:50.208 10682-10687/com.mad.losesano I/zygote: After code cache collection, code=108KB, data=82KB
03-16 17:35:51.113 10682-10687/com.mad.losesano I/zygote: Do partial code cache collection, code=108KB, data=81KB
03-16 17:35:51.113 10682-10687/com.mad.losesano I/zygote: After code cache collection, code=108KB, data=81KB
03-16 17:35:51.113 10682-10687/com.mad.losesano I/zygote: Increasing code cache capacity to 512KB
03-16 17:35:52.131 10682-10707/com.mad.losesano V/FA: Inactivity, disconnecting from the service
03-16 17:35:55.022 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:55.039 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:55.210 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:55.238 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:57.257 10682-10687/com.mad.losesano I/zygote: Do full code cache collection, code=249KB, data=182KB
03-16 17:35:57.257 10682-10687/com.mad.losesano I/zygote: After code cache collection, code=246KB, data=155KB
03-16 17:35:59.190 10682-10682/com.mad.losesano D/LoSeSANO: Email Address: oshaughnessycian@gmail.com
03-16 17:35:59.200 10682-10682/com.mad.losesano W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
03-16 17:35:59.805 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:35:59.850 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:03.637 10682-10707/com.mad.losesano V/FA: Recording user engagement, ms: 17110
03-16 17:36:03.637 10682-10707/com.mad.losesano V/FA: Connecting to remote service
03-16 17:36:03.642 10682-10707/com.mad.losesano V/FA: Activity paused, time: 10686585
03-16 17:36:03.649 10682-10707/com.mad.losesano D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=17110, firebase_screen_class(_sc)=SignupActivity, firebase_screen_id(_si)=359863105737247052}]
03-16 17:36:03.650 10682-10682/com.mad.losesano V/FA: onActivityCreated
03-16 17:36:03.673 10682-10687/com.mad.losesano I/zygote: Do partial code cache collection, code=248KB, data=164KB
03-16 17:36:03.675 10682-10687/com.mad.losesano I/zygote: After code cache collection, code=248KB, data=164KB
03-16 17:36:03.675 10682-10687/com.mad.losesano I/zygote: Increasing code cache capacity to 1024KB
03-16 17:36:03.679 10682-10707/com.mad.losesano V/FA: Connection attempt already in progress
03-16 17:36:03.722 10682-10707/com.mad.losesano D/FA: Connected to remote service
03-16 17:36:03.722 10682-10707/com.mad.losesano V/FA: Processing queued up service tasks: 2
03-16 17:36:03.734 10682-10682/com.mad.losesano V/FA: onActivityCreated
03-16 17:36:03.785 10682-10707/com.mad.losesano V/FA: Activity resumed, time: 10686732
03-16 17:36:03.790 10682-10707/com.mad.losesano D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SignupActivity, firebase_previous_id(_pi)=359863105737247052, firebase_screen_class(_sc)=LoggedInActivity, firebase_screen_id(_si)=359863105737247053}]
03-16 17:36:03.922 10682-10687/com.mad.losesano I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
03-16 17:36:03.922 10682-10687/com.mad.losesano I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
03-16 17:36:03.982 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:04.110 10682-10682/com.mad.losesano I/AssistStructure: Flattened final assist data: 2632 bytes, containing 1 windows, 8 views
03-16 17:36:05.339 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:05.388 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:05.408 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:05.420 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:06.405 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:36:06.405 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:36:06.603 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:36:06.603 10682-10682/com.mad.losesano E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-16 17:36:08.875 10682-10707/com.mad.losesano V/FA: Inactivity, disconnecting from the service
03-16 17:36:11.858 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:11.888 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:12.024 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:12.055 10682-10709/com.mad.losesano D/EGL_emulation: eglMakeCurrent: 0xa177dd40: ver 3 0 (tinfo 0xa17aa670)
03-16 17:36:16.324 10682-10682/com.mad.losesano D/AndroidRuntime: Shutting down VM
03-16 17:36:16.325 10682-10682/com.mad.losesano E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mad.losesano, PID: 10682
java.lang.IllegalStateException: Could not find method btnClicked(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.Button with id 'login_button'
at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:5368)
at android.view.View$DeclaredOnClickListener.onClick(View.java:5327)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
答案 0 :(得分:0)
试试另一种方法,如何在xml中设置按钮onClick属性:
<Button
android:text="A"
android:id="@+id/A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:onClick="btnClicked"
android:layout_weight="1" />
并在LoginActivity中实现btnClicked方法:
public void btnClicked(View view) {
//on click code goes here
}
答案 1 :(得分:0)
从按钮中移除android:onClick="btnClicked"
属性。
将您的Activity
更改为AppCompatActivity
(可选,但最佳)
在您的布局中,更改
app:layout_constraintTop_toBottomOf="@+id/login_button"
代表
app:layout_constraintTop_toBottomOf="@id/login_button"
和
app:layout_constraintTop_toBottomOf="@+id/register_tv"
的
app:layout_constraintTop_toBottomOf="@id/register_tv"
所有内容都设置正确,但使用@+id
为ConstraintLayout生成引用会生成一个新引用,这显然是运行时代码正在拾取的内容。如果先前已定义,则可以引用所提及的ID,就像您的情况一样。
答案 2 :(得分:0)
无法找到解决方案。最终取消了该项目并重新开始。