我是Firebase的新手,所以非常感谢对此的见解。当我以这种方式调用Firebase setValue(obj,callback)函数时,它可以完美地工作。但是,当我试图删除“ref”引用的值时,没有任何反应。这只是一个测试帐户,因此我将安全规则设置为完全读写。输出如下。一些输出来自一个调用removeNode(...)的封装run()方法。任何见解都非常赞赏。
public void removeNode(final Firebase ref) throws Exception {
try {
System.out.println("Start Remove Node: " + ref.toString());
final AtomicBoolean done = new AtomicBoolean(false);
ref.removeValue(new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
done.set(true);
System.out.println("Remove Node complete");
if (firebaseError != null) {
System.out.println("ErrorCode: " + firebaseError.getCode());
System.out.println("ErrorMsg: " + firebaseError.getMessage());
}
System.out.println("Remove Complete Done");
}
});
while (!done.get()) {
Thread.sleep(500);
System.out.println("Remove Node Sleeping");
}
} catch (Exception e) {
System.out.println("Remove Node Exception: " + e.getMessage());
}
}
我的输出如下:
in run() - about to removeNode https://<instance>.firebaseio.com/node/node
Start Remove Node: https://<instance>.firebaseio.com/node/node
Remove Node Sleeping
Remove Node Sleeping
Remove Node complete
Remove Complete Done
Remove Node Sleeping
in run() - RemoveNode leaving normally
pool-3-thread-1
All threads handled so far? {true}
Complete
Process finished with exit code 0
注意:我的结果与此类似。
ref.setValue(null, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
done.set(true);
System.out.println("setNull Node complete");
if (firebaseError != null) {
System.out.println("ErrorCode: " + firebaseError.getCode());
System.out.println("ErrorMsg: " + firebaseError.getMessage());
} else {
System.out.println("FirebaseError: NULL");
}
System.out.println("setNull Complete Done");
}
});
答案 0 :(得分:2)
您用于删除的Firebase网址为https://BLAH/node/node
它应该是https://BLAH/node吗?
获取网址并将其粘贴到浏览器中,以便在Forge中查看,然后仔细检查数据是否存在。