-2

When my app runs on S3, it crashes when it contains code to convert String from Textview to int. Here it is:

tv = (TextView) findViewById(R.id.counter_txt);
String txtNum = (String) tv.getText();
Toast.makeText(getApplicationContext(), new Integer(txtNum), Toast.LENGTH_SHORT).show();

The scenario is I put a number on screen, and it increase by one when user clicks. But when I convert the String number to int, it crashes. Someone knows it? Thank you.

user1683941
  • 163
  • 1
  • 1
  • 5

2 Answers2

1
tv = (TextView) findViewById(R.id.counter_txt);
String txtNum  = tv.getText().toString();
Integer intNum = Integer.valueOf(txtNum); 
Toast.makeText(getApplicationContext(), txtNum, Toast.LENGTH_SHORT).show();
X7S
  • 409
  • 1
  • 4
  • 10
0

Make it new Integer(txtNum).to string() . May be it will work I guess

Saurabh Chaturvedi
  • 2,028
  • 2
  • 18
  • 39