When I add "var applicationDate = (clubEvent.start...
# android
s
When I add "var applicationDate = (clubEvent.startParticipationDate.toString(DateTimeFormat.forPattern("' 'dd-MM-yyyy' 'HHmmss' '")))" to my app, whenever I go to that page in the app, the app crashes.
🧵 1
I have no idea why, and I am trying to make it into a variable so I can call it in multiple places.
k
Look in logcat... Probably a null pointer exception
You'll see a stacktrace there
s
Alright, I will take a look
Can I copy the error message here? I dont understand it
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property clubEvent has not been initialized
n
clubEvent has not been set, this error is somewhere else
☝️ 1
s
The weird thing is, I can use the clubEvent.startParticipationDate by itself but not if I want to make a variable out of it
n
probably because that whole line is optimized out if you don't make a variable
you need to make sure clubEvent is set to something non-null before running that line
s
How can I do that? Sorry I am new to Kotlin
k
It has nothing to do with kotlin.... You have to set that variable...
o
You have an uninitialized
lateinit var clubEvent: ClubEvent
in your code. Before accessing that variable you have to assign a value to it. https://kotlinlang.org/docs/properties.html#late-initialized-properties-and-variables You probably have the following code:
Copy code
class MyClass {
    lateinit var clubEvent: ClubEvent
    var applicationDate = clubEvent[...]
}
`applicationDate`'s initialization is trying to read a the uninitialized
clubEvent
property
If you are unable to figure things out going forward from this, better post in #getting-started with proper formatting, error messages and code snippets. They'll help you out. This is just essential Kotlin knowledge without any ties to Android. Further discussion should not take place in #android but rather #getting-started
s
Alright, thank you Ondrej for the help. I will try to figure it out myself with the links you provided and then turn to #getting-started if I need more help.
k
And also keep the discussion to a thread instead of posting another message at the top level