0
 var items: Int by Delegates.notNull<Int>() db.collection("Testdatabase").get().addOnSuccessListener{ snap-> items=snap.size() } Log.i("items",items.toString()) 

and it says

Property items should be initialized before get 

I have to use 'items' variable as a size of the snapshot. I searched some google but I can't figure out.. Can any one help please?

1
  • 2
    You must assign some value to items before you use them inside the Log. Remember that the Log statement will be executed first due to synchronous execution and then the items=snap.size() line So you must assign some value to items Commented Sep 8, 2021 at 12:15

1 Answer 1

1

That happens because your addOnSuccessListener takes some time to get data. So in this example, you need to put your log statement inside addOnSuccessListener and you will be fine

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Thank you for telling me the reason!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.