So this is my code right now but the app still crashes when I run this:
db.collection("historyCal").document(idData.toString()).get()
.addOnSuccessListener { document ->
if (document != null) {
val calin = document.get("calInDay") as List<*>
calin.forEach {
Log.d("someTag",calin.toString())
}
} else {
Log.d("noexist", "No such document")
}
}
I have data that consists of:
- collection: historyCal
- document: id user I already put on variable idData
- fields: callInDay, it's an array consist of a number (2000,2100,2000)
I want to get data from callInDay and print each value with a log:
The error log :
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.joshua.testapp, PID: 27966 kotlin.TypeCastException: null cannot be cast to non-null type kotlin.collections.List<*> at com.joshua.testapp.HistoryActivity$setBarChartValues$1.onSuccess(HistoryActivity.kt:45) at com.joshua.testapp.HistoryActivity$setBarChartValues$1.onSuccess(HistoryActivity.kt:18) at com.google.android.gms.tasks.zzn.run(Unknown Source:4) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
line 45 : val calin = document.get("calInDay") as List<*> line 18 : class HistoryActivity : AppCompatActivity() { //i think this is due to line 45
Can someone help me? Thanks