0

This is my code on Android(doesn't work) -> error -

com.firebase.client.FirebaseException: Failed to bounce to type at 
com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183) at 
ua.deti.cm.pt.livingcity.MainFragment$1.onDataChange(MainFragment.java:83) at 
com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)

---- code ----

Firebase.setAndroidContext(getActivity().getApplicationContext());
        Firebase mRef;
        mRef = new Firebase("https://livingcityapp.firebaseio.com");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String currentDateandTime = sdf.format(new Date());
        Firebase usersRef = mRef.child(currentDateandTime);
        HashMap<String, Object> mapaCompleto = new HashMap<>();
        usersRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Log.i("There are", dataSnapshot.getChildrenCount() + "dados");
                for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
                    FireBaseDataClass post = postSnapshot.getValue(FireBaseDataClass.class);
                    Log.i("o que é isto?", post.getHora()+ " - " + post.getTemperature()+ " - " + post.getHumidade());
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
                Log.i("The read has failed", firebaseError.getMessage());
            }
        });

---link to Firebase -> https://livingcityapp.firebaseio.com/
Prune
  • 76,765
  • 14
  • 60
  • 81
  • You have a mismatch between your JSON and your `FireBaseDataClass`. The exception lower in the stack trace will tell you what is wrong. [This question+answer](http://stackoverflow.com/questions/32108969/why-do-i-get-failed-to-bounce-to-type-when-i-turn-json-from-firebase-into-java) gives you the most likely fixes. – Frank van Puffelen Apr 01 '16 at 01:16
  • Here is my Class it fully matches the firebase i have only Strings, i saw you link to the other thread, still dont works :S --Print of Firebase: http://prntscr.com/amu7vd public class FireBaseDataClass { private String Hora; private String Humidade; private String Latitude; private String Longitude; private String Temperature; public FireBaseDataClass() { // empty default constructor, necessary for Firebase to be able to deserialize blog posts } public String getHora() { ... } – Tomás Rodrigues Apr 01 '16 at 16:11
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase database. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. Also put the code in your questions. There's an [edit](http://stackoverflow.com/posts/36345693/edit) link right under it for that. – Frank van Puffelen Apr 01 '16 at 16:18
  • Thanks Frank i got it, from another way, but it works now, much thanks. – Tomás Rodrigues Apr 02 '16 at 13:22

0 Answers0