错误行:
尝试在空对象引用上调用虚拟方法'com.google.firebase.database.ValueEventListener com.google.firebase.database.DatabaseReference.addValueEventListener(com.google.firebase.database.ValueEventListener)'
Database.java
package com.juliusj.gym.easygym;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class Database{
DatabaseReference mRef;
List<Kontaktas> mList = new ArrayList<>();
mRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https://easygym-jj173.firebaseio.com/Users");
public List<Kontaktas> sarasas(){
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mList.clear();
//shake hands
for (DataSnapshot unit : dataSnapshot.getChildren()){
Kontaktas value = unit.getValue(Kontaktas.class);
mList.add(value);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return mList;
}
}
答案 0 :(得分:0)
改变这个:
mRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https://easygym-jj173.firebaseio.com/Users");
到此:
mRef = FirebaseDatabase.getInstance().getReference().child("Users");
您也无需添加网址来引用数据库。