0

I am having an issue. Whenever I delete the last child the complete parent node is deleted. Due to which my application crashes. Is there a way to only delete child without deleting complete node. This is the code on which the app crashes.

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) {

                }
            });

This is the code to remove the data.

rootNode2.child(Pname).removeValue();
        Toast.makeText(this, "Place Deleted", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(getApplicationContext(),UnderReviewPlaces.class));
        finish();
Anonymous Asked question May 14, 2021