Android Can';t从Firebase检索数据';s节点
我正在开发一个Android应用程序,我正在使用Firebase作为数据库。 我想从中获取特定节点,但检索这些数据失败 我已经编写了Firebase的安全规则,这是我的数据结构: 这是我的Android代码:Android Can';t从Firebase检索数据';s节点,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我正在开发一个Android应用程序,我正在使用Firebase作为数据库。 我想从中获取特定节点,但检索这些数据失败 我已经编写了Firebase的安全规则,这是我的数据结构: 这是我的Android代码: public void connect() { //setting connexion parameter final Firebase ref = new Firebase("https://test.firebaseio.com/test"); Query q
public void connect() {
//setting connexion parameter
final Firebase ref = new Firebase("https://test.firebaseio.com/test");
Query query = ref.orderByChild("longitude").equalTo("150");
//get the data from th DB
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//checking if the user exist
if(dataSnapshot.exists())
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
//get each user which has the target username
final Location location = userSnapshot.getValue(Location.class);
//if the password is true , the data will be storaged in the sharedPreferences file and a Home activity will be launched
System.out.println("hello map"+location.getLongitude());
}
System.out.println("not found");
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("problem ");
}
});
}
这是location类
public class Location {
private String longitude,latitude;
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
@Override
public String toString() {
return "Location{" +
"longitude=" + longitude +
", latitude=" + latitude +
'}';
}
public Location(String longitude, String latitude) {
this.longitude = longitude;
this.latitude = latitude;
}
}在location类中定义一个空构造函数。我尝试了它,但它不起作用。您的查询正在查找一个等于150的变量,我看不出您的查询如何使用当前显示的数据集检索某些内容。您有一个异常?我将其更改为105,但它不起作用:)问题是没有使用hashmap插入的节点