这是我的Java类:
public class OnlineMatch{
private FacebookUser firstplayer;
private FacebookUser secondplayer;
public OnlineMatch(){
}
public OnlineMatch(FacebookUser firstplayer, FacebookUser secondplayer) {
this.firstplayer = firstplayer;
this.secondplayer = secondplayer;
}
public FacebookUser getFirstplayer() {
return firstplayer;
}
public void setFirstplayer(FacebookUser firstplayer) {
this.firstplayer = firstplayer;
}
public FacebookUser getSecondplayer() {
return secondplayer;
}
public void setSecondplayer(FacebookUser secondplayer) {
this.secondplayer = secondplayer;
}
我可以正确创建对象并上传到Firebase。数据库结构如下:
![从 Firebase 面板控制中获取的屏幕截图](https://istack.dev59.com/jdNie.webp)
然后,我尝试打印我的OnlineMatch对象的值(Kotlin代码):
val match = dataSnapshot.child("multiplayer").getValue(OnlineMatch::class.java)
if(match!=null){
System.out.println(match)
}
这里是我在Android Studio控制台上获得的输出:
9548-19548/app.simone W/ClassMapper: 在app.simone.multiplayer.model.OnlineMatch类中找不到-KqV44f4FUxV8ZDuqL4Y的setter/field。
08-01 19:14:38.816 19548-19548/app.simone W/ClassMapper: 在app.simone.multiplayer.model.OnlineMatch类中找不到-KqV3sAPXPcYrtr61cDy的setter/field。
08-01 19:14:38.816 19548-19548/app.simone W/ClassMapper: 在app.simone.multiplayer.model.OnlineMatch类中找不到-KqV2BGH7Z-Y9RxnPGpt的setter/field。
code fun createMatch(match: OnlineMatch) { var database = FirebaseDatabase.getInstance().getReference("multiplayer") val matchList = database.push() matchList.setValue(match) }
- Giacomo Bartoli