Unsolved reference

I have the following code…

    val beaconConnection = BeaconConnection(reactContext, beacon, object : BeaconConnection.ConnectionCallback {

        override fun onConnected(beaconInfo: BeaconInfo?) {
            log("onConnected() -  ${beacon.proximityUUID}")

            beaconConnection.motionState().getAsync(object : Property.Callback<MotionState> {
                override fun onFailure() {

                override fun onValueReceived(value: MotionState?) {
                    log("${beacon.proximityUUID} - $value")

        override fun onAuthorized(beaconInfo: BeaconInfo?) {

        override fun onAuthenticationError(exception: EstimoteDeviceException) {
            log("onAuthenticationError - ${exception.printStackTrace()}")

        override fun onDisconnected() {


The line beaconConnection.motionState().getAsync(object : Property.Callback { has an unresolved reference error and i’m am trying to use the outside variable inside the class later on
In Java if I declare this as final this would work but I am not sure how to get around this in Kotlin

I could do this at the start…
var beaconConnection: BeaconConnection? = null

    beaconConnection = BeaconConnection(reactContext, beacon, object : BeaconConnection.ConnectionCallback {

and then do null checks
beaconConnection?.motionState()?.getAsync(object : Property.Callback {

But I am trying to avoid this

How can I access the variable beaconConnection in the inner class?

You can’t use an uncreated object. At first, you should create an object and then you can use it. Try to set Callback using a setter function. But it is not possible to use a nonexisting object.