user9502627
user9502627

Reputation:

Could not execute method for android:onClick ERROR

I want to display a number text that increases if the statement is true and to show the number in a text view, the error comes when I change the text view text when the number is increased.

 int stars = 0; //Global variable

//onClick{...}

public void changeTextViewToStarsNumber(){
  if(editText.getText().equals("153"){
     stars = stars + 10;
     textView.setText(stars); //The error line
  }
}

Upvotes: 0

Views: 52

Answers (3)

Sourish Mukherjee
Sourish Mukherjee

Reputation: 179

.setText() needs a String value You need to convert your starts to a String type, by using valueOf() function.

Upvotes: 0

Squti
Squti

Reputation: 4467

Change the error line to textView.setText(String.valueOf(stars));

Upvotes: 2

Giorgos Neokleous
Giorgos Neokleous

Reputation: 1767

Is your error at compilation? If so, then I am guessing you need to parse your stars into a String.

textView.setText(String.valueOf(stars)); //The error line

Upvotes: 1

Related Questions