Global variable assigned with applicationContext.filesDir

Hello, I am new in Kotlin.
I have searched a solution on the web before posting this topic bit did not find one.

I want to to set a global val variable (vDataFile) at startup that I want use in any function in the MainActivity class but the program crashes when reaching that second line. Could anyone tell me what is wrong?

class MainActivity : AppCompatActivity() {
val vDataFile = File(applicationContext.filesDir, “data.txt”)
override fun …

THANKS

You should post a stack trace of your error. For what it’s worth, in the snippet you posted you’re not defining a global but a property of MainActivity.