0

I have to retrive the user data from realtime data in profileActivity. I have saved the data inside the "Users" node of the database, but when i wants to fetch it logcat shows the error onDataChange

Error shows on line inside the ProfileActivity at: User value = snapshot.getValue(User.class)

        databaseReference.child(userId).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
    
                    User value = snapshot.getValue(User.class);
    
                    if (user != null){
                        String fullname = value.name;
                        String email = value.email;
                        String phone = value.phone;
    
                        fullnametextview.setText(fullname);
                        emailtextview.setText(email);
                        phonetextview.setText(phone);
                    }
    
            }
    
            @Override
            public void onCancelled(@NonNull DatabaseError error) {
                Toast.makeText(ProfileActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show();
            }
        });
    
    }

}```

Reference of my database is "Users".

"Users": {
    "Dy4SkpgT0qdV0hAWCR05FlyUhN73": {
      "email": "juaavha@gmail.com",
      "name": "Wjshsb",
      "phone": "6434843482"
    },

Here is the error shows inside the logcat :

I/InputTransport: Create ARC handle: 0xb40000785af1b120
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@82c8817, this = DecorView@804ba58[ProfileActivity]
V/OplusZoomWindowDecorViewHelper: setLastReportedMergedConfiguration mZoomDisplayHeight: 2400 getDecorView.DecorView@804ba58[ProfileActivity]
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@df32955, this = DecorView@6ee3b5e[Dashboard]
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.studystudio.enggdarbar, PID: 5601
    com.google.firebase.database.DatabaseException: Class com.studystudio.enggdarbar.User does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:570)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:563)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(CustomClassMapper.java:433)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(CustomClassMapper.java:232)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:80)
        at com.google.firebase.database.DataSnapshot.getValue(DataSnapshot.java:203)
        at com.studystudio.enggdarbar.ProfileActivity$1.onDataChange(ProfileActivity.java:55)
        at com.google.firebase.database.Query$1.onDataChange(Query.java:191)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
        at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:255)
        at android.app.ActivityThread.main(ActivityThread.java:8212)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
I/Process: Sending signal. PID: 5601 SIG: 9
Aditya
  • 1
  • 2
  • Please edit your question to show: 1) the exact error message and stack trace, e.g. by throwing or logging `error.toException()`. 2) the data at `databaseReference.child(userId)` in your database (as text, no screenshots please). You can get this by clicking the "Export JSON" link in the overflow menu (⠇) on your [Firebase Database console](https://console.firebase.google.com/project/_/database/data). – Frank van Puffelen Mar 01 '23 at 03:45
  • Please edit your question and add the information Frank asked for, and please also respond using @. – Alex Mamo Mar 01 '23 at 09:28
  • @AlexMamo I have edited and added the necessary details – Aditya Mar 01 '23 at 16:05
  • Please add the entire error message that you get. – Alex Mamo Mar 01 '23 at 16:25
  • @AlexMamo added.. please check it now – Aditya Mar 01 '23 at 16:35

0 Answers0