I am trying to fetch a value from firebase like so:
private String getVCount(String mPath) {
ArrayList<String> strings = new ArrayList<>();
FirebaseDatabase.getInstance().getReference("cars").child(mPath).child("maserati")
.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull @NotNull Task<DataSnapshot> task) {
if(task.isSuccessful()){
strings.add(task.getResult().getValue().toString());
}else{
strings.add("0");
}
}
});
Log.d("mString", String.valueOf(strings.size()));
return strings.get(0);
}
I double checked the path, and even added an else condition just to make it so that the strings array list has at least one value in it.
The value in the database does exist, and does not exist in some cases--hence the else statement to add a default value of 0. I'm not sure if this is the correct way to do that though.
Additionally, I'm still getting the error: Index: 0 Size: 0--meaning that the strings array list is empty.
Any idea why this may be so?
Thanks.