enter code hereE/AndroidRuntime: FATAL EXCEPTION: main
Process: jdp.term5.babysittr, PID: 12904
java.lang.RuntimeException: Unable to start activity ComponentInfo{jdp.term5.babysittr/jdp.term5.babysittr.Register}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process jdp.term5.babysittr. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
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: Default FirebaseApp is not initialized in this process jdp.term5.babysittr. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:1)
at jdp.term5.babysittr.utility.firebasemethods.<init>(firebasemethods.java:31)
at jdp.term5.babysittr.Register.onCreate(Register.java:51)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
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)
I / Process:正在发送信号。 PID:12904 SIG:9
我创建并注册了一个页面,其中包含电子邮件,用户名和密码,并将其加载到我的Firebase数据库中。但我似乎遇到了麻烦。
public class Register extends AppCompatActivity {
private static final String TAG = "Register";
private Context mContext;
private String email, username, password;
private EditText mEmail, mPassword, mUsername;
private TextView loadingPleaseWait;
private Button btnRegister;
private ProgressBar mProgressBar;
// firebase
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private firebasemethods Firebasemethods;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Firebasemethods = new firebasemethods(mContext);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mContext = Register.this;
Log.d(TAG, "onCreate: started.");
initWidgets();
setupFirebaseAuth();
init();
}
private void init() {
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
email = mEmail.getText().toString();
username = mUsername.getText().toString();
password = mPassword.getText().toString();
if (checkInputs(email, username, password)) {
mProgressBar.setVisibility(View.VISIBLE);
loadingPleaseWait.setVisibility(View.VISIBLE);
Firebasemethods.registerNewEmail(email, password, username);
profileNav();
}
}
});
}
private boolean checkInputs(String email, String username, String password) {
Log.d(TAG, "checkInputs: checking inputs for null values.");
if (email.equals("") || username.equals("") || password.equals("")) {
Toast.makeText(mContext, "All fields must be filled out.", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
/**
* Initialize the activity widgets
*/
private void initWidgets() {
Log.d(TAG, "initWidgets: Initializing Widgets.");
mEmail = (EditText) findViewById(R.id.sign_in_email);
mUsername = (EditText) findViewById(R.id.register_username);
btnRegister = (Button) findViewById(R.id.register_button);
// mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
// loadingPleaseWait = (TextView) findViewById(R.id.loadingPleaseWait);
mPassword = (EditText) findViewById(R.id.register_password);
mContext = Register.this;
mProgressBar.setVisibility(View.GONE);
loadingPleaseWait.setVisibility(View.GONE);
}
private boolean isStringNull(String string) {
Log.d(TAG, "isStringNull: checking string if null.");
if (string.equals("")) {
return true;
} else {
return false;
}
}
private void setupFirebaseAuth() {
Log.d(TAG, "setupFirebaseAuth: setting up firebase auth.");
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// ...
}
};
}
@Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
private void profileNav() {
Intent profileNavIntent = new Intent(Register.this, profile.class);
startActivity(profileNavIntent);
finish();
}
}
我不明白未初始化的Firebase是什么意思
我尝试过
super.onCreate();
// FirebaseApp.initializeApp(this);
但是我不知道它去了哪里,我也不知道它是否能解决我的难题
答案 0 :(得分:0)
FirebaseApp.initializeApp(this)
应该进入扩展Application
的类。例如:
public class ThisIsMyApp extends Application {
@Override
public void onCreate(){
super.onCreate();
FirebaseApp.initializeApp(this);
}
}
如果它仍然无法在Google上运行,则似乎是一个基本问题:)在此处查看更多解决方案:Default FirebaseApp is not initialized