0

I am a beginner in programming and I'm trying to retrieve these data sent by raspberry pi from Arduino. What do you think is the problem?

!Firebase Database Image I've tried multiple tutorial videos and the answers on similar problems on this site but I still can't retrieve the data.

This is the current code:

public class ph extends AppCompatActivity {

    ArrayList <String> list;
    ArrayAdapter <String> adapter;
    phlevel phlvl;

    private static final String TAG = "phlevel";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ph);

        phlvl = new phlevel();
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference mRef = database.getReference("phlevel");
        final ListView mListView = (ListView) findViewById(R.id.listView);
        list = new ArrayList<>();
        adapter = new ArrayAdapter<String>(this,R.layout.activity_ph,R.id.phlevelinfo,list);


        mRef.addChildEventListener(new ChildEventListener() {

            @Override
            public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            }

            @Override
            public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
            {
                if(dataSnapshot.child("date").exists() &&
                        dataSnapshot.child("time").exists() &&
                        dataSnapshot.child("value").exists()) {
                    Log.d(TAG,"onChildChanged: " + dataSnapshot.toString());
                }

            }

This is the phlevel code:

public class phlevel {

    private String date;
    private String time;
    private String value;

    public phlevel(String date, String time, String value) {
        this.date = date;
        this.time = time;
        this.value = value;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

And this is the XML for the ph activity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ph">

    <TextView
        android:id="@+id/phlevelinfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:text="Displaying pH Level"
        android:textSize="30sp"
        tools:ignore="HardcodedText" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="30dp" />


</LinearLayout>

I am expecting that the values in "date, time, and value" from the database be retrieved and listed on ListView. Instead, the app shows nothing except the text "Displaying pH Level". Thank you.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • If you try to add `Log.d(TAG,"onChildAdded: " + dataSnapshot.toString());` in your `onChildAdded()` method is something printed out in the logcat? – Alex Mamo Oct 06 '19 at 08:25
  • `2019-10-06 17:02:17.297 2161-2161/system_process E/LoadedApk: Unable to instantiate appComponentFactory java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/system/priv-app/GoogleSdkSetup/lib/x86_64, /system/lib64, /system/lib64]]` this printed out on the Logcat error. I tried to search for the answer which led me here [link](https://stackoverflow.com/questions/51006967/androidx-build-fails-in-release-mode-regarding-appcomponentfactory) but it still printed out the error. – Justin Chan Oct 06 '19 at 09:10
  • I don't recall having the "Unable to instantiate appComponentFactory" error a while ago. Other error includes [link](https://imgur.com/a/ObGdNmI) . – Justin Chan Oct 06 '19 at 09:18

0 Answers0