【发布时间】:2021-05-14 03:12:24
【问题描述】:
我遇到了问题。每当我删除最后一个子节点时,都会删除完整的父节点。因此我的应用程序崩溃了。有没有办法只删除子节点而不删除完整节点。这是应用程序崩溃的代码。
Review.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
reviewcount = (int) snapshot.getChildrenCount();
ReviewCount.setText(Integer.toString(reviewcount));
} else {
ReviewCount.setText(0);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
这是删除数据的代码。
rootNode2.child(Pname).removeValue();
Toast.makeText(this, "Place Deleted", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),UnderReviewPlaces.class));
finish();
【问题讨论】:
-
哪个部分崩溃了?
-
上面的代码在我的 MainActivity 类中。所以,一旦我启动应用程序,它就会崩溃。
标签: android firebase firebase-realtime-database