Home > Net >  getting an error when using toDouble() and toIntOrNull()
getting an error when using toDouble() and toIntOrNull()

Time:09-27

I'm writing a simple tip calculator app in android studio ( which is one of the programs in the And here is the screenshot of the error

Any help is appreciated!!

CodePudding user response:

Try after removing
import java.text.NumberFormat comment

  fun calculateTip() {
    val stringInTextField = binding.costOfService.text.toString()
    val cost = stringInTextField.toDouble()
    }

build & clean

uncomment the code in above method you will get correct import

CodePudding user response:

Seems like you do not have the latest kotlin support . Update the Kotlin version to the latest one from : File ->> Setting -->> Language & Frameworks -->> Kotlin ...

CodePudding user response:

Use

val cost = Double.parseDouble(stringInTextField)
  • Related