我目前正在使用Firebase进行数据库管理的Android应用程序上工作。我已经创建了一个登录屏幕,但是在启动时,该应用会立即加载并退出。我厌倦了清理项目,在模拟器上卸载和安装应用程序,调试以及对应用程序进行操作。
这是我用于登录屏幕的代码
public class MainActivity extends AppCompatActivity {
private EditText mEmailField;
private EditText mPasswordField;
private Button mLoginBtn;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
mEmailField = (EditText)findViewById(R.id.emailField);
mPasswordField = (EditText)findViewById(R.id.passwordField);
mLoginBtn = (Button)findViewById(R.id.loginBtn);
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser() !=null) {
startActivity(new Intent(MainActivity.this, Account.class));
}
}
};
mLoginBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
startSignIn();
}
});
}
@Override
protected void onStart(){
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
private void startSignIn() {
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
Toast.makeText(MainActivity.this, "fields are empty", Toast.LENGTH_LONG).show();
} else {
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete (@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(MainActivity.this, "sign in fail", Toast.LENGTH_LONG).show();
}
}
});
}
}
}
我在这里附上了我的logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.fireapp, PID: 12509
java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:
at android.app.ActivityThread.installProvider(ActivityThread.java:6396)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException:
at com.google.android.gms.internal.ads.zzmn.attachInfo(Unknown Source:17)
at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(Unknown Source:3)
at android.app.ActivityThread.installProvider(ActivityThread.java:6391)
... 10 more