我正在构建我的应用程序,并显示构建成功,但是当我尝试在我的设备中运行时,它表明您的应用程序再次停止打开,如果有人帮助我解决此问题,则仅在登录活动中会发生这种情况,请帮助我
我的登录活动代码
package com.eassycars.www.licencespot;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
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 Activity_Login extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
private Button singups,forgotpass,logins;
RelativeLayout really1, really2;
Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
really1.setVisibility(View.VISIBLE);
really2.setVisibility(View.VISIBLE);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
startActivity(new Intent(Activity_Login.this, MainActivity.class));
finish();
}
// set the view now
setContentView(R.layout.activity__login);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
singups = (Button) findViewById(R.id.singups);
logins = (Button) findViewById(R.id.logins);
forgotpass = (Button) findViewById(R.id.forgotpass);
//Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
singups.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Activity_Login.this, singup.class));
}
});
forgotpass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Activity_Login.this, ForgotPassword.class));
}
});
really1 = (RelativeLayout) findViewById(R.id.rellayl);
really2 = (RelativeLayout) findViewById(R.id.really2);
handler.postDelayed(runnable, 2000);
logins.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(Activity_Login.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
progressBar.setVisibility(View.GONE);
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {
inputPassword.setError(getString(R.string.minimum_password));
} else {
Toast.makeText(Activity_Login.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
} else {
Intent intent = new Intent(Activity_Login.this, MainActivity.class);
startActivity(intent);
finish();
}
}
});
}
});
}
}
这些是我的登录活动代码,无法找到错误,并且android studio还显示您没有任何错误,但是有一个错误是当我使用登录屏幕时我的应用程序不断停止。
我使用Firebase构建登录活动
答案 0 :(得分:0)
请从logcat发布您的错误消息。
如果从线程调用Handler导致NullPointerException,
尝试在handler
中致电您的onCreate
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
//move this HERE!!
new Handler().post(new Runnable() {
@Override
public void run() {
// Code here will run in UI thread
}
});
}
}