1
val editText1 = findViewById<EditText>(R.id.editText1);

if(comNum != editText1.toString().toInt() ){

 View4.text = "오답"
            } else View4.text = "정답"

The installed apk is not working. I think edittext.toString.toInt is wrong.

firegloves
  • 5,581
  • 2
  • 29
  • 50
유재언
  • 21
  • 3

5 Answers5

6

Get the String out of EditText: editText1.getText().toString().toInt()

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

Wrong

 editText1.toString().toInt()

It should be

editText1.text.toString().toInt()

FYI

toInt() Parses the string as an Int number and returns the result. if the string is not a valid representation of a number you will receive NumberFormatException .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

Try this

 val editText1 = findViewById<EditText>(R.id.editText1);

  if(comNum != Integer.parseInt(editText1.text.toString()) ){

     View4.text = "오답"
        } else View4.text = "정답"
Maitri
  • 513
  • 1
  • 3
  • 14
1

Try below code, you can not using editText1.toString().toInt()

  var value: Int

  try {
         value =  editText1.text.toString().toInt();
  } catch (e: NumberFormatException) {
         // value of editText1 is a invalid Integer
  }
  if(comNum != value ){
  View4.text = "오답"
  } else View4.text = "정답"

hope this helps

GianhTran
  • 3,443
  • 2
  • 22
  • 42
0

Use

editText1.text.toString().toInt()
AskNilesh
  • 67,701
  • 16
  • 123
  • 163