0

I know that there are a lot of posts like this but I read them and my application does not work yet. Im trying to convert TextView parameter into int. I use this:

int MyScore;
TextView score = (TextView) findViewById(R.id.highscore);
MyScore = Integer.parseInt(score.toString());

When im launching the program and rich to the place this should work my program crushing becasue of the last line: MyScore = Integer.parseInt(score.toString());

How can I solve this?

Omri Attiya
  • 3,917
  • 3
  • 19
  • 35

2 Answers2

2

Your last line should read

    MyScore = Integer.parseInt(score.getText().toString());

The toString() method called on your score object describes the score object, it does not return the string entered into the score object. Please refer to the Oracle Java tutorials. It is a good idea to read through most of them.

Floris
  • 1,082
  • 10
  • 26
  • using TextView.getText().toString() (like @Floris suggested) will return the text of the TextView. Works same for EditText if you will ever need. – Omri Attiya May 05 '17 at 06:36
0

Because you didn't specify the language used I cannot answer fully, but I can guess what the problem is. Most input fields have a value or text property, try parsing that.

SBoss
  • 8,845
  • 7
  • 28
  • 44