作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
当我尝试使用 Firebase 获取数据时遇到了这个问题:
No setter/field for 0C:F3:EE:12:E0:4C found on class com.school.models.EmBeacon
No setter/field for 0C:F3:EE:12:E0:5C found on class com.school.models.EmBeacon
No setter/field for 0C:F3:EE:12:E0:E5 found on class com.school.models.EmBeacon
这是我的数据结构:
这是获取我所有数据的代码:
mDatabase.child("beacons").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
EmBeacon mBeacon = dataSnapshot.getValue(EmBeacon.class);
Log.i(TAG, "onDataChange: "+mBeacon);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.w(TAG, "onCancelled:", databaseError.toException());
}
});
和类(class):
public class EmBeacon {
private String proximityUuid;
private int major;
private int minor;
private String addressMac;
public EmBeacon() {
}
public EmBeacon( String addressMac) {
this.addressMac = addressMac;
}
public EmBeacon(String proximityUuid, int major, int minor, String addressMac) {
this.proximityUuid = proximityUuid;
this.major = major;
this.minor = minor;
this.addressMac = addressMac;
}
public String getProximityUuid() {
return proximityUuid;
}
public void setProximityUuid(String proximityUuid) {
this.proximityUuid = proximityUuid;
}
public int getMajor() {
return major;
}
public void setMajor(int major) {
this.major = major;
}
public int getMinor() {
return minor;
}
public void setMinor(int minor) {
this.minor = minor;
}
public String getAddressMac() {
return addressMac;
}
public void setAddressMac(String addressMac) {
this.addressMac = addressMac;
}
@Override
public String toString() {
return "EmBeacon{" +
"proximityUuid='" + proximityUuid + '\'' +
", major='" + major + '\'' +
", minor='" + minor + '\'' +
", addressMac='" + addressMac + '\'' +
'}';
知道这里出了什么问题吗?
最佳答案
/beacons
下有多个信标,所以你需要在你的onDataChange
中循环它们:
mDatabase.child("beacons").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot beaconSnapshot: dataSnapshot.getChildren()) {
EmBeacon mBeacon = beaconSnapshot.getValue(EmBeacon.class);
Log.i(TAG, "onDataChange: "+mBeacon);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.w(TAG, "onCancelled:", databaseError.toException());
}
});
关于java - 重复的 : No setter/field for found on class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51026552/
我是一名优秀的程序员,十分优秀!