无法将java.lang.String类型的对象转换为com.example.andrija.dogymate.DogUser类型

时间:2018-05-17 20:52:42

标签: java nullpointerexception

  

无法将java.lang.String类型的对象转换为type   com.example.andrija.dogymate.DogUser           在com.google.android.gms.internal.firebase_database.zzkt.zzb(未知   资源)           在com.google.android.gms.internal.firebase_database.zzkt.zza(未知   资源)           在com.google.firebase.database.DataSnapshot.getValue(未知来源)处   com.example.andrija.dogymate.ProfileActivity $ 1.onChildAdded(ProfileActivity.java:51)                         在com.google.android.gms.internal.firebase_database.zzbt.zza(未知   资源)                         在com.google.android.gms.internal.firebase_database.zzgx.zzdr(未知   资源)                         在com.google.android.gms.internal.firebase_database.zzhd.run(未知   资源)                         在android.os.Handler.handleCallback(Handler.java:761)                         在android.os.Handler.dispatchMessage(Handler.java:98)                         在android.os.Looper.loop(Looper.java:156)                         在android.app.ActivityThread.main(ActivityThread.java:6623)                         at java.lang.reflect.Method.invoke(Native Method)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:942)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

错误在上面,我尝试了一切,比如直接将数据输入数据库,但它没有用。我环顾了StackOverFlow,我试图使用这些答案,但每次出现错误都没有帮助。

user=FirebaseAuth.getInstance().getCurrentUser();
        databaseReference2= FirebaseDatabase.getInstance().getReference("Users").child(user.getUid());
        databaseReference2.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                DogUser dogUser=dataSnapshot.getValue(DogUser.class);
                txtDoggyName.setText(dogUser.getDogname());
                txtOwnersName.setText(dogUser.getUsername());
                txtAge.setText(dogUser.getDogage());
                txtBreed.setText(dogUser.getDogbreed());
                txtSex.setText(dogUser.getDogsex());
                ArrayList<String> c=dogUser.getDogcharacter();
                String t="";
                for(int i=0;i<c.size();i++)
                    t=t+c.get(i)+" ";
                txtCharacter.setText(t);
            }
            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
            }
            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
            }
            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            }
            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });

0 个答案:

没有答案