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)
1
  • 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. Commented Nov 25, 2021 at 3:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.