0

I am trying to read data once from my firebase but my app keeps crashing below is what my database looks like enter image description here

The below is my code

public void checkUserStatus(){

        final String ID = firebaseAuth.getCurrentUser().getUid();
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference();
        myRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                User user = dataSnapshot.child("UserDetails").child(ID).child("Type").getValue(User.class);
                textView.setText(user.getTrueFalse());
            }

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

            }
        });
    }

Error

2019-12-06 20:31:32.595 13211-13211/com.example.smartdoor E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.smartdoor, PID: 13211
    com.google.firebase.database.DatabaseException: Class com.example.smartdoor.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(com.google.firebase:firebase-database@@19.2.0:569)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-database@@19.2.0:562)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.2.0:432)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.0:231)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.2.0:79)
        at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.2.0:203)
        at com.example.smartdoor.SignOutFragment$2.onDataChange(SignOutFragment.java:79)
        at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.2.0:179)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.0:75)
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.0:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.0:55)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Theo
  • 1
  • 1
  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. – Alex Mamo Dec 06 '19 at 20:09
  • If you do a google search for this error message, you will find a lot of information about it, as you can see from the duplicates. – Doug Stevenson Dec 06 '19 at 21:19

1 Answers1

0

Add a no argument constructor to class User:

public User() {
} 
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134