Your First Kotlin Android App - Part 22: Adding | Ray Wenderlich

Learn about properties and how to add them to an activity.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4738-your-first-kotlin-android-app/lessons/22

Kind of surprised you make the folks learn about findViewById when you have the the kotlin-android-extensions at their disposal. So, instead of doing what you did you could have just had them reference the widgets directly via their name…game_score_text_view for example.

We actually do that in later series. This is just one method to get them started.

Gotcha. Thanks for explaining.

1 Like

Why is my “internal” and "var " red in the mainActivity codes??

It sounds there is an error occurring. Typically, when you see red in any code editor then you are making a mistake or the code can’t figure out what is happening. Is you statements inside the class definition? That’s the first thing I’d check.

If so, feel free to paste the code here and I’ll take a look. Thanks!

Sk%C3%A4rmklipp

This is how it looks like right now.
Can I restart my MainActivity or something?
So I can get It back to original.

It looks like you are missing your opening brace . Add the opening brace at the end of the class definition line or underneath it. That is, the line that reads: “class MainActivity extends …”

That will resolve all your errors. I hope that helps!

I think Android Studio/Kotlin has been improved such that type inference is better. I get a warning in the OnCreate method when I add the type to the findViewById call (findViewById<Button>, etc.)

@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]