尝试在空对象引用上调用虚拟方法'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()'

时间:2018-12-20 10:43:33

标签: java android firebase firebase-authentication

直到今天早上我在android studio中运行代码并崩溃时,我的应用程序才能正常运行,我检查了logcat并指出了这两个地方

第一个位于MainActivity.java的{​​{1}}

onStart

第二名在我的 mAuth = FirebaseAuth.getInstance(); mToolbar = findViewById(R.id.main_app_bar); setSupportActionBar(mToolbar); getSupportActionBar().setTitle("ChatPlus"); BottomNavigationView navigation = findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); loadFragment(new RequestFragment()); if (mAuth.getCurrentUser() != null) { mUserRef = FirebaseDatabase.getInstance().getReference().child("Users").child(mAuth.getCurrentUser().getUid()); } } @Override public void onStart() { super.onStart(); //crashes here // Check if user is signed in (non-null) and update UI accordingly. FirebaseUser currentUser = mAuth.getCurrentUser(); if (currentUser == null) { sendtostart(); } else { mUserRef.child("online").setValue("true"); } } @Override protected void onStop() { super.onStop(); FirebaseUser currentUser = mAuth.getCurrentUser(); if (currentUser != null) { mUserRef.child("online").setValue(ServerValue.TIMESTAMP); } }

RequestFragment

0 个答案:

没有答案