I want to display a message when one of the two EditTexts is empty.
A.toString () == "" || B.toString () == ""
                 ->Toast.makeText (this, "No number entered !!", Toast.LENGTH_SHORT) .show ()

In the above part
1. Expecting'->'
2.Expecting an expression, is-condition or in-condition
Error is displayed and cannot be resolved. Could you teach me?

Corresponding source code
class MainActivity: AppCompatActivity (), View.OnClickListener {
    override fun onCreate (savedInstanceState: Bundle?) {
        super.onCreate (savedInstanceState)
        setContentView (R.layout.activity_main)
        setContentView (R.layout.editor_layout)
        button1.setOnClickListener (this)
        button2.setOnClickListener (this)
        button3.setOnClickListener (this)
        button4.setOnClickListener (this)
    override fun onClick (v: View?) {
        val intent = Intent (this, SecondActivity :: class.java)
          // Get the EditText string and convert it to a number
          val A = editText1.text.toString (). toDouble ()
          val B = editText2.text.toString (). toDouble ()
         when (v? .id) {
             R.id.button1->intent.putExtra ("VALUE", (A + B))
             R.id.button2->intent.putExtra ("VALUE", (A --B))
             R.id.button3->intent.putExtra ("VALUE", (A * B))
             R.id.button4->intent.putExtra ("VALUE", (A/B))
            else else
                this.A.toString () == "" || this.B.toString () == ""
                 ->Toast.makeText (this, "No number entered !!", Toast.LENGTH_SHORT) .show ()
        startActivity (intent)
  • Answer # 1

    Cause of the error?

    I think that the else clause is the part that passes when none of the conditions are met, so isn't it possible to write the condition after else?
    Isn't the else of the relevant part unnecessary?

    else else
        A.toString () == "" || B.toString () == ""
            ->Toast.makeText (this, "No number entered !!", Toast.LENGTH_SHORT) .show ()
    Before that, is the logic correct?

    Looking at the when statement, the blank check is in the same when statement as when the clicked button was 1-4.

    Since when selects one from multiple processes and executes it, it seems that the intention is that if the clicked one is any of the four buttons, the blank check part will not pass.

    Perhaps either "check for whitespace on any button clicked = there is a whitespace check outside the when statement" or "check for whitespace only when a specific button is clicked = when" There is a blank check in the section ", isn't it the intended specification?