Firebase对象

时间:2017-08-01 23:21:58

标签: android firebase firebase-realtime-database kotlin

这是我的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。 db结构如下: Screenshot taken from firebase panel control

然后我尝试打印我的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

2 个答案:

答案 0 :(得分:1)

您的代码要求multiplayer下的所有,其中包含您之前推送过的所有OnlineMatch对象。您可以从错误消息中看到它正在尝试查找在-KqV44f4FUxV8ZDuqL4Y下找到的推送ID multiplayer的setter或字段。如果您想获取单个OnlineMatch对象,那么您将必须挖掘multiplayer下推送ID中的对象。所以这应该给你一些东西:

dataSnapshot.child("multiplayer/-KqV44f4FUxV8ZDuqL4Y").getValue(OnlineMatch::class.java)

无论如何,您需要拥有自己选择的推送ID,或者从快照的子项中发现它们,并从该子项构建新的快照。

答案 1 :(得分:0)

道格史蒂文森,你的回答对我有用。 我创建了一个字符串数组,在那里我保存了密钥,然后我为每个特定的密钥遍历子项:

[2017-08-02 13:08:55,194] [a6b3228d] Replication to git@git.something.com:/vt-test.git started...
[2017-08-02 13:08:55,320] [a6b3228d] Push to git@git.something.com:/vt-test.git references: [RemoteRefUpdate[remoteName=refs/heads/master, NOT_ATTEMPTED, (null)...990c876ff3860fbfd421a9785c87506126b89d1b, srcRef=refs/heads/master, message=null]]
[2017-08-02 13:08:55,379] [a6b3228d] Cannot replicate to git.something.com:/vt-test.git
org.eclipse.jgit.errors.TransportException: git.something.com:/vt-test.git: reject HostKey: git.something.com
    at      org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:160)    
    at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:137)
    at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:322)
    at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:167)
    at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:160)
    at org.eclipse.jgit.transport.Transport.push(Transport.java:1272)
    at org.eclipse.jgit.transport.Transport.push(Transport.java:1318)
    at com.googlesource.gerrit.plugins.replication.PushOne.pushVia(PushOne.java:437)
    at com.googlesource.gerrit.plugins.replication.PushOne.runImpl(PushOne.java:416)
    at com.googlesource.gerrit.plugins.replication.PushOne.runPushOperation(PushOne.java:318)
    at com.googlesource.gerrit.plugins.replication.PushOne.access$000(PushOne.java:86)
    at com.googlesource.gerrit.plugins.replication.PushOne$1.call(PushOne.java:284)
    at com.googlesource.gerrit.plugins.replication.PushOne$1.call(PushOne.java:281)
    at com.google.gerrit.server.util.RequestScopePropagator$5.call(RequestScopePropagator.java:221)
    at com.google.gerrit.server.util.RequestScopePropagator$4.call(RequestScopePropagator.java:200)
    at com.google.gerrit.server.git.PerThreadRequestScope$Propagator$1.call(PerThreadRequestScope.java:75)
    at com.googlesource.gerrit.plugins.replication.PushOne.run(PushOne.java:281)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at com.google.gerrit.server.git.WorkQueue$Task.run(WorkQueue.java:417)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.jcraft.jsch.JSchException: reject HostKey: git.something.com
    at com.jcraft.jsch.Session.checkHost(Session.java:791)
    at com.jcraft.jsch.Session.connect(Session.java:342)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:117)
    ... 24 more