我无法从Java(非android)检索firebase数据库。我已经创建了Firebase数据库,如下所示:
public static void main(String[] args) throws FileNotFoundException, IOException{
FileInputStream serviceAccount = new FileInputStream("D:/xxxxxxxxxx-x9314-firebase-adminsdk-d8he2-4ab7b5976b.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://xxxxxxxxx-x9314.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
DatabaseReference ref = FirebaseDatabase.getInstance()
.getReference("cars");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object car = dataSnapshot.getValue();
System.out.println(car);
}
@Override
public void onCancelled(DatabaseError error) {
}
});
}
运行应用程序时没有数据出现。
请问有人可以帮我吗?