https://kotlinlang.org logo
#android
Title
# android
s

Shane Blackburn

02/11/2019, 8:52 PM
Hi all! I created a Kotlin file in my project that is a data class that colds an array of questions and answers. I can't figure out how to access that array in my main activity! Any ideas? Thanks!
s

Seri

02/11/2019, 8:56 PM
Can you post a sample from that data class?
t

tseisel

02/11/2019, 8:57 PM
Supposing this is your data class :
Copy code
data class Faq(val questions: List<Question>, answers: List<Answer>)
Create it with
Copy code
val qa = Faq(listOf(...), listOf(...))
Access it with
Copy code
val questions = qa.questions
✔️ 1
s

Seri

02/11/2019, 8:58 PM
Would it be better implemented as a Hashmap?
d

dewildte

02/11/2019, 10:20 PM
A data class is not a static object it needs to be instantiated.