0

I have stored the data on Firebase as follows:

                   mlist=dbHandler.getAllContacts(1);
                   for (int i=0;i<mlist.size();i++) {
                         reportModel = mlist.get(i);
                         ref = new Firebase(Config.FIREBASE_URL);
                         Firebase userRef = ref.child(mUserId);
                         Map newUserData = new HashMap();
                         newUserData.put("Sno", reportModel.getSno());
                         newUserData.put("level", reportModel.getLevel());
                         newUserData.put("rounds", reportModel.getRounds());
                         newUserData.put("date", reportModel.getDate());
                         newUserData.put("time", reportModel.getDatesep());
                                                                                                      userRef.push().setValue(newUserData);
                         mref=userRef.push();
                          newId=mref.getKey();
                     }

Now I want to retrieve all the data from the Firebase database for a specific user. I have written the code as:

                for (DataSnapshot ds: dataSnapshot.getChildren()) {
                reportModel = new ReportModel();
                reportModel.setSno(ds.getValue(ReportModel.class).getSno());
                reportModel.setLevel(ds.getValue(ReportModel.class).getLevel());
                reportModel.setRounds(ds.getValue(ReportModel.class).getRounds());
                reportModel.setDatesep(ds.getValue(ReportModel.class).getDatesep());

                mlist.add(reportModel);
            }
            if(mlist.size()>0){
                adapter = new ReportAdapter(mContext, R.layout.adapter_layout,
                        mlist);

                // Binds the Adapter to the ListView
                listview.setAdapter(adapter);
            }

But the app is crashing with the error :

com.firebase.client.FirebaseException: Failed to bounce to type

I want that if I delete the data from the ListView then after clicking button the data to be retrieved from Firebase and stored on ListView.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
shruity
  • 178
  • 1
  • 2
  • 16
  • There is usually a good error in the stack trace when you get `Failed to bounce to type`. See [this Q&A](http://stackoverflow.com/questions/32108969/why-do-i-get-failed-to-bounce-to-type-when-i-turn-json-from-firebase-into-java) for the most common causes. Unless you provide the **minimum complete** code that reproduces the error, I vote to close your question as a duplicate of that one as it enumerates the likely causes. – Frank van Puffelen Aug 29 '16 at 14:35

1 Answers1

0

The error stats that Firebase is not able to map its data to the defined class.

Check if:

1) ReportModel has an empty constructor.

2) ReportModel variables and Firebase fields have the same name.

3) Map data the following way:

reportModel = ds.getValue(ReportModel.class);
M.Waqas Pervez
  • 2,492
  • 2
  • 19
  • 33