Paul Clapham wrote:If I understand the code correctly: You create a listener and tell it to wait for something to happen (and when the something happens it should assign a value to a class-level variable). Then immediately you check the class-level variable, and no surprise, it hasn't had a value assigned to it yet.
Although I don't see where the variable named "employee" is declared, so maybe I'm misunderstanding the question and you're really asking why the code doesn't compile?
I'm using a NoSQL database from Firebase, and I'm using the listener to retrieve all the data in the database to find the specific data for the current user. The problem is that the instance of the
Employee class is
null after attaching the listener to the reference. The listener reads data when it is first attached or when there is a change in the database. Also, I can assign local variables within the listener's scope without getting null values. It's almost like the compiler doesn't recognize the assignment of the data to the outside variable at runtime. My goal was just to retrieve the user's data from the listener and assign it to an instance variable outside the listener's scope - then detach the listener.
You can get information on the listener from:
Read and Write Data