java.util.Objects.requireNonNull处的java.lang.NullPointerException(由于此错误,基于Firebase的应用程序崩溃了)

时间:2019-01-24 13:22:52

标签: java android firebase firebase-realtime-database

这是我关于 Stackoverflow 的第一个问题。以某种方式完成我的最后一年的项目,我指的是Youtube视频。

我的问题是:

我想从 Firebase Database 检索个人资料图片,并希望  在导航标题上显示图像(即显示导航标题    个人资料图片),并在我创建的设置活动中显示该个人资料图片。

但是运行该应用程序后,它继续崩溃。 这是错误:

java.lang.NullPointerException at
   java.util.Objects.requireNonNull Error.

日志

2019-01-24 17:55:18.199 6533-6533/academy.learnprogramming.subjoin I/Choreographer: Skipped 11 frames!  The application may be doing too much work on its main thread.
2019-01-24 17:55:18.233 6533-6533/academy.learnprogramming.subjoin I/AssistStructure: Flattened final assist data: 2600 bytes, containing 1 windows, 8 views
2019-01-24 17:55:19.620 6533-6533/academy.learnprogramming.subjoin D/AndroidRuntime: Shutting down VM
2019-01-24 17:55:19.621 6533-6533/academy.learnprogramming.subjoin E/AndroidRuntime: FATAL EXCEPTION: main
    Process: academy.learnprogramming.subjoin, PID: 6533
    **java.lang.NullPointerException
        at java.util.Objects.requireNonNull(Objects.java:203)
        at academy.learnprogramming.subjoin.MainActivity$1.onDataChange(MainActivity.java:92)**
        at com.google.android.gms.internal.firebase_database.zzfc.zza(Unknown Source:13)
        at com.google.android.gms.internal.firebase_database.zzgx.zzdr(Unknown Source:2)
        at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source:71)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:187)
        at android.app.ActivityThread.main(ActivityThread.java:7025)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:514)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
2019-01-24 17:55:19.636 6533-6533/academy.learnprogramming.subjoin I/Process: Sending signal. PID: 6533 SIG: 9

错误块:MainActivity.java:92

UsersRef.child(currentUserID).addValueEventListener(new ValueEventListener() 
{
            @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) 
{

           if (dataSnapshot.exists())
            {

                String fullname = Objects.requireNonNull(dataSnapshot.child("fullname").getValue(String.class));
                String image = Objects.requireNonNull(dataSnapshot.child("profileimage").getValue(String.class));

                NavProfileUserName.setText(fullname);
                Picasso.get().load(image).placeholder(R.drawable.profile).into(NavProfileImage);

            }

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError)
        {

        }
    });

0 个答案:

没有答案