[Help] I can’t call a textview using a function (Android Studio)

FIXED

Hello everyone!

This is my first week in programming so basically, I’m new to everything.

Anyway, I’m trying to create a mini game as instructed by the tutor of a programming course, but for some reason the same code he wrote is not working for me. However, if I download his code, it works perfectly fine.

The problem is for some reason the textviews cannot be called from anywhere inside the mainactivity.kt (I have given the textview that I want to code with an ID, but for some reason android studio does not recognize it)

The code is simple :


class MainActivity : AppCompatActivity() { var score : Int = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) score = 0 } fun increaseScore(view: View) { score++ scoreText.text= "Score $score" } }

The error I get is “Unresolved reference” and it is at line: scoreText.text= “Score $score”

Any help would be appreciated because this error is driving me nuts especially when I have been searching for a solution for 2h+

Edit: Forgot to mention that the course is a bit old (pre the release of android studio 3.0) so it could be something that got changed since then

submitted by /u/Qwerty-er
[link] [comments]