```class CustomLayout : RelativeLayout { ...
# announcements
p
Copy code
class CustomLayout : RelativeLayout {

    
    constructor(context: Context) : super(context)
    
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    private var mGlucoseState = GlucoseState.NONE
...

    override fun onCreateDrawableState(extraSpace: Int): IntArray {
        
        val drawableState = super.onCreateDrawableState(extraSpace + 7)

        when (mGlucoseState) { // Crashing because mGlucoseState is null

            GlucoseState.LOW -> View.mergeDrawableStates(
                drawableState,
                STATE_GLUCOSE_LOW
            )

            GlucoseState.DANGER_LOW -> View.mergeDrawableStates(
                drawableState,
                STATE_GLUCOSE_WARN_LOW
            )

            ... 

            else -> View.mergeDrawableStates(
                drawableState,
                STATE_GLUCOSE_NONE
            )

        }

        return drawableState
    }

...

}