0

I am following a beginner's android development course on Udacity and have seemed to come across a simple error, though I cannot for the life of me figure it out or how to search for it.

There is just a number with an increment and decrement button on the sides to change it. The problem comes either when I call the displayQuantity method or when it tries to set the text of the quantityTextView. The value of quantity does change, but the app closes before it changes on the screen.

    public void increment (View view){
    quantity = quantity + 1;
    displayQuantity(quantity);
    }

    public void decrement (View view){
    quantity = quantity - 1;
    displayQuantity(quantity);
    }

    private void displayQuantity(int quantity) {
    TextView quantityTextView = (TextView)  findViewById(R.id.quantity_text_view);
    quantityTextView.setText(quantity);
}
KalebB
  • 11
  • 4

1 Answers1

2

Change to

quantityTextView.setText(Integer.toString(quantity));

TextView.setText() is overloaded. The version that takes an integer expects a resource identifier for a string resource (e.g. R.string.something), but the value you are passing doesn't correspond to any such resource.

Karakuri
  • 38,365
  • 12
  • 84
  • 104