1. Are you ready for the Galaxy S20? Here is everything we know so far!

cannot retrieve data from realtime firebase database

Discussion in 'Android Apps & Games' started by nurulaida, Jun 8, 2021.

  1. nurulaida

    nurulaida Lurker
    Thread Starter

    I want to retrieve data from realtime firebase database into my android studio app. I am using TextView to display the data however it gives me an error. The data from firebase won't display in the TextView. can someone help me with this error..tqq

    this is my error message

    2021-06-09 03:01:09.992 11837-11837/com.fyp.airpollutiondetection E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.fyp.airpollutiondetection, PID: 11837
    com.firebase.client.FirebaseException: Failed to bounce to type
    at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)
    at com.fyp.airpollutiondetection.reading$1.onDataChange(reading.java:30)
    at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)
    at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
    at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
    Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
    at [Source: java.io.StringReader@2f78e27; line: 1, column: 1]
    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:46)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
    at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:181)
    ... 11 more

    I also get this message

    2021-06-09 03:00:57.215 11837-11837/? E/lutiondetectio: Unknown bits set in runtime_flags: 0x8000

    This is my code

    package com.fyp.airpollutiondetection;

    import androidx.appcompat.app.AppCompatActivity;

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;

    import com.firebase.client.DataSnapshot;
    import com.firebase.client.Firebase;
    import com.firebase.client.FirebaseError;
    import com.firebase.client.ValueEventListener;

    public class reading extends AppCompatActivity {
    private TextView nilai;
    private Firebase mRef;

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reading);

    nilai = (TextView)findViewById(R.id.nilai);
    mRef = new Firebase("https://air-pollution-7917c-default-rtdb.firebaseio.com/CARBON");
    mRef.addValueEventListener(new ValueEventListener() {
    @override
    public void onDataChange(DataSnapshot dataSnapshot) {
    String CARBON = dataSnapshot.getValue(String.class);
    nilai.setText(CARBON);
    }

    @override
    public void onCancelled(FirebaseError firebaseError) {
    }
    });
    }
    }
     



    1. Download the Forums for Android™ app!


      Download

       

Android Studio Tutorial

Android Studio Tutorial Forum

com.androidstudio.tutorial

READ MORE
July 22, 2020
Last Updated
2.6
Rating
Installs
Loading...
Similar Threads - cannot retrieve data
  1. ixoni
    Replies:
    8
    Views:
    378
  2. oneytlam
    Replies:
    2
    Views:
    314
  3. Christopher Clayton
    Replies:
    0
    Views:
    228
  4. robertanisoiu
    Replies:
    1
    Views:
    762
  5. etijskens
    Replies:
    3
    Views:
    435
  6. Provasek
    Replies:
    5
    Views:
    548
  7. dorlow
    Replies:
    4
    Views:
    1,268
  8. Marlz
    Replies:
    3
    Views:
    687
  9. lancred
    Replies:
    1
    Views:
    337
  10. Not_Rich
    Replies:
    7
    Views:
    662

Share This Page

Loading...