# Your First Kotlin Android App - Part 25: Handling | Ray Wenderlich

**URL:** <https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550>\
**Category:** 🎓 Courses & Articles\
**Created:** [March 21, 2018, 3:36am UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550 "2018-03-21T03:36:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [March 21, 2018, 3:36am UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/1 "2018-03-21T03:36:15Z")

</div>

If you want to react to events, you need to write some actions. This video will show you how.

* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/4738-your-first-kotlin-android-app/lessons/25](https://www.raywenderlich.com/4738-your-first-kotlin-android-app/lessons/25)

---

<div class="post-metadata">

**Author:** ![marathoner1234](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marathoner1234/32/110937_2.png) [@marathoner1234](https://forums.kodeco.com/u/marathoner1234)\
**Post date:** [February 23, 2019, 5:39am UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/2 "2019-02-23T05:39:30Z")

</div>

With Android Studio version 3.3.1, we can populate the onClick property in the Attributes navigator with a method name that is to be executed when the button is tapped. Would this not be preferable to adding a listener in the onCreate method in the Activity?

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [February 25, 2019, 9:57pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/3 "2019-02-25T21:57:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gundrabur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gundrabur/32/80503_2.png) [@gundrabur](https://forums.kodeco.com/u/gundrabur)\
**Post date:** [February 26, 2019, 3:32pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/4 "2019-02-26T15:32:47Z")

</div>

concerning method “incrementScore()”  
why do I have to store the new score into a variable “newScore”?  
I can simply write it in the UI directly, like this:  
gameScoreTextView.text = getString(R.string.your\_score, score.toString())  
It is working fine and I will save one line of code and a variable …

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [February 28, 2019, 9:55pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/5 "2019-02-28T21:55:39Z")

</div>

Thanks for the comment @gundrabur. It’s always good to write less code for sure! But for instruction in a course like this, it’s also good to add some code verbosity to add clarity for people with less development experience. Experienced developers will tend to optimize this choice.

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [February 28, 2019, 9:56pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/6 "2019-02-28T21:56:47Z")

</div>

Thanks for the question @marathoner1234. In many ways this is often up to the preference of the developer. In certain cases, it’s more efficient to add the listeners in XML, in other cases, in Kotlin.

---

<div class="post-metadata">

**Author:** ![gundrabur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gundrabur/32/80503_2.png) [@gundrabur](https://forums.kodeco.com/u/gundrabur)\
**Post date:** [March 1, 2019, 8:56am UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/7 "2019-03-01T08:56:24Z")

</div>

Thanks for the information. I am new to Kotlin and thought I had misunderstood something. By the way: Great workshop. I love it!

---

<div class="post-metadata">

**Author:** ![gabe.wilk](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gabe.wilk/32/81494_2.png) [@gabe.wilk](https://forums.kodeco.com/u/gabe.wilk)\
**Post date:** [May 22, 2019, 6:56pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/8 "2019-05-22T18:56:41Z")

</div>

Hi, on line 29 of the tutorial, Android Studio is throwing me the error “Format string ‘your\_score’ is not a valid format string so it should not be passed to String.format”

Upon compiling, I click the button on the emulator and my app crashes.

Any thoughts? my code looks identical to the tutorial.  
Thanks!  
gabe

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [May 22, 2019, 7:18pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/9 "2019-05-22T19:18:29Z")

</div>

This course hasn’t been updated yet. It’s in the works, but you want to update the line to look like the following:

```
val newScore = getString(R.string.your_score, Integer.toString(score))

```

Notice that I’m calling Integer.toString only this time, I’m passing in the score. You’ll do this in other areas as well. As always, if you get stuck, feel free to reach out.

Cheers!

---

<div class="post-metadata">

**Author:** ![loutfy1](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/loutfy1/32/81494_2.png) [@loutfy1](https://forums.kodeco.com/u/loutfy1)\
**Post date:** [June 19, 2019, 3:07pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/10 "2019-06-19T15:07:18Z")

</div>

Hi

I’m getting two errors while trying to run the app

![C](https://files.chunter.kodeco.com/original/3X/a/8/a8fe837b7336c6f2eba1e9e28f0370121f4cf9e9.png)

Can you help in this?

---

<div class="post-metadata">

**Author:** ![bdmoakley](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bdmoakley/32/108772_2.png) [@bdmoakley](https://forums.kodeco.com/u/bdmoakley)\
**Post date:** [June 24, 2019, 4:07pm UTC](https://forums.kodeco.com/t/your-first-kotlin-android-app-part-25-handling-ray-wenderlich/40550/11 "2019-06-24T16:07:03Z")

</div>

lateinit is used when you don’t have the reference of a variable when the object is created. These are for variables that are not supposed to be null. By declaring a variable as a lateinit, you are telling the compiler that when the object is created, the value will be null, but that null will be gone will the object is actually used.

You are using score as an int. This contains a value. It’s not like an object that requires a reference. When using primitive types (int, double, float, bool), you provide a default value. To solve this error, you just remove the lateinit keyword because it’s not needed. I hope that helps.
