gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:13:58 25 4
gpt4 key购买 nike

我在我的处理程序上面临上述问题,该处理程序每​​次都会检查您是否登录,但我面临这个问题,我该如何解决?

伙计们,我已经尝试了几种方法,但我仍然遇到同样的问题,这是每次都会检查的启动屏幕,因此应用程序崩溃了。

这是我的欢迎屏幕

```public class WelcomeScreen extends AppCompatActivity {

private ImageView logo;
private FirebaseAuth firebaseAuth;
private FirebaseDatabase firebaseDatabase;
private static int SPLASH_TIME_OUT = 5000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullscreen ();
setContentView (R.layout.welcomescreen);
firebaseAuth = FirebaseAuth.getInstance ();
final String user_id = firebaseAuth.getCurrentUser ().getUid ();
final FirebaseUser firebaseUser = firebaseAuth.getInstance ().getCurrentUser ();
firebaseDatabase = FirebaseDatabase.getInstance ();
final DatabaseReference databaseReference = firebaseDatabase.getReference ().child ("Users").child (user_id);





logo= findViewById (R.id.logoocaap);

Animation animation = AnimationUtils.loadAnimation (this,R.anim.splashscreen);
logo.startAnimation (animation);



new Handler ().postDelayed (new Runnable () {
@Override
public void run() {


//check if there's internet connection


checkConnection();



if(firebaseUser != null)
{

databaseReference.addValueEventListener (new ValueEventListener () {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {```

最佳答案

首先检查 FirebaseUser 是否为 null,然后尝试获取 UID。检查以下内容:

firebaseAuth = FirebaseAuth.getInstance ();
final FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
String user_id = "";

if(firebaseUser != null)
user_id = firebaseUser.getUid ();

当前您尝试在 FirebaseUser 上获取 UID,该 UIDnull

关于java - 我无法解决尝试在空对象引用上调用虚拟方法 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59155530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com