0

app close everysingle time i run

var editTextH:EditText? = null
var editTextW:EditText? = null
var result:TextView? = null

val h: Float = editTextH?.text.toString().toFloat() / 100 
val w: Float = editTextW?.text.toString().toFloat()
val res: Float = w/(h*h)
Over Time
  • 21
  • 4
  • Where is this code snipped you pasted located? In an activity? Is "editTextH" still null? It sounds like you converted a null value to a string "null" then tried to convert it to a number. To debug it yourself, try breaking that command up into several steps and printing out the intermediate values. – Tyler V Nov 25 '21 at 03:47

1 Answers1

0

Its usually because the input given from your EditText is not match with your expectation that is Float. try to use: editTextH?.text?.toString().trim().toFloat() the trim() will remove if any space character on the input given y EditText.

and please next to include your error log not only the Exception. So we can try to analyze on what line that the Exception cause.