Firebase retrieve data Problem, Child Element wird nicht angesprochen

Den4Coding

Mitglied
Hallo an alle,

ich habe folgendes Problem, ich benutzte seit kurzem Firebase realtime database um Daten dort zu speichern um später diese abzufragen. So sieht meine database Struktur aus.
firebase database.jpg
Ich versuche nun bestimmte Daten per JAVA abzufragen um in Variablen dann zu speichern. Ich möchte zum Beispiel Timestamp1 abfragen, wenn ich jedoch Timestamp1 anspreche, wird mir der ganze Inhalt mir angezeigt, was ich nicht will.
Hier ist mein Code, was tue ich falsch? Würde sehr dankbar sein für jede Hilfe.

[CODE lang="java" title="Firebase realtime database retrieve data"]import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.database.*;

import javax.naming.Name;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;


public class DatabaseData {

public static void main(String[] args) throws IOException, InterruptedException {
FileInputStream serviceAccount = new FileInputStream("./google-services.json");
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://myExampleProject.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);

class timestampuno {
public String Time;

public timestampuno(String Timestamp1) {
this.Time = Timestamp1;
System.out.println("Timestamp:" + Time);

}
}

final DatabaseReference dataref = FirebaseDatabase.getInstance().getReference("users");
CountDownLatch latch = new CountDownLatch(1);
dataref.orderByChild("Timestamp1").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String prevChildKey) {
timestampuno Timestamp = dataSnapshot.getValue(timestampuno.class);
System.out.println(dataSnapshot.getKey() + Timestamp);
}

@Override
public void onChildChanged(DataSnapshot snapshot, String previousChildName) { }

@Override
public void onChildRemoved(DataSnapshot snapshot) { }

@Override
public void onChildMoved(DataSnapshot snapshot, String previousChildName) { }

@Override
public void onCancelled(DatabaseError error) { }

});
latch.await();

}

}[/CODE]
 
Zuletzt bearbeitet:

Ähnliche Java Themen

Neue Themen


Oben