'How to refer to LinearLayout in program code?

I am new to Kotlin and Android Studio. I'm trying to create a "Snake" game. I created a RelativeLayout and added two LinearLayouts to it. The first is for displaying the score, the second for the field of play and the snake itself. But when accessing the second LinearLayout via Id, I get an error. I also want to ask for help. I don't want to create a simple "snake", I'm trying to create a "beautiful" game. Like Google games "Snake". And who could help with my questions and writing code, could we go to the chat?)enter image description here

enter image description here



Solution 1:[1]

You should get the reference of linear layout in activity like this

val llayout : LinearLayout = findViewById(R.id.snake)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashish Gautam