简体   繁体   中英

getting error java.lang.NumberFormatException: empty String

need to multiply numbers in 2 textbox (numbers can be integer or double) and display result in textview box on clicking the button btn_warp but i am getting the java.lang.NumberFormatException: empty String error

class SootCalc:AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.sootcalc)

        btn_warp.setOnClickListener {

            val wpreed = txt_warpReed.text.toString().toDouble()
            val wppanna=txt_warpPanna.text.toString().toDouble()
            
            if(txt_warpReed.text.isEmpty()){
                txtViewWarp.text=""
                return@setOnClickListener
            }
            val result1=(wpreed*wppanna)
             txtViewWarp.text= result1.toString()
        }

    }
}

        

try this:

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.sootcalc)

btn_warp.setOnClickListener {

    val wpreed = txt_warpReed.text.toString()
    val wppanna = txt_warpPanna.text.toString()
    
    if(wpreed == "" || wppanna == ""){
        txtViewWarp.text = ""
    } else {
        val result1=(wpreed.toDouble()*wppanna.toDouble())
        txtViewWarp.text= result1.toString()
    }
}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM