Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int cannot be converted to string?

I am trying to write the instructions to notice when circle is about to be 12 and then add 1 to square.

The code below works fine for me

   int x = Integer.parseInt(circle.getText()); 
   x = x + 1;
   String z = Integer.toString(x);
   circle.setText(z);

However, I am having trouble with these new instructions I am trying to write. How can I get square, convert to integer, add 1 and then put the value back?

   int q = Integer.parseInt(square.getText());
   x = q + 1;
   square.setText(x);
like image 223
Vestel Avatar asked Mar 18 '26 15:03

Vestel


1 Answers

You can convert to String using Integer.toString() :

square.setText(Integer.toString(x));
like image 84
Eran Avatar answered Mar 21 '26 06:03

Eran