I really hope, you can help me here:
I'm trying to create a Class "Cloud" where all the Firestore-Stuff is happening.
But I can't overwrite Attributes with Firestore Values and work with them in my Main-Activity. It will always give me a Null-Object-Reference-Error.
Example
Inside my Cloud-Class I have an Attribute "theTest". With the Method "Test()" I now want to overwrite this Attribute with a Value of my Firestore Database:
public String Test(){
db.collection("Products").whereEqualTo("isAvailable", true).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
theTest = queryDocumentSnapshots.getDocuments().get(0).getId();
}
});
return theTest;
}
Now in my Main-Activity, I want to use this value just like:
String test = cloud.Test();
Log.d("TheTest", test);
But it's not working! I always get the same Null Object Reference Error.
I don't know what exactly I'm doing wrong..
Thank you in Advance!