'TextView SetText

I have a problem.
In line "textView.setText(money + "$");" my program crashes.
(money is int, and textView1 is ID of my TextView)

public TextView textView;
public void onCashClick(View view) {
    money++;
    textView = (TextView) view.findViewById(R.id.textView1);
    textView.setText(money + "$");
}


Solution 1:[1]

Cause the view you are using for binding the text view is the clicked button, instead of using view.findViewById() if your are in a activity just use findViewById and if your are in a fragment use your rootView.

Solution 2:[2]

Simply remove view that is before findViewByID to be like this

textView = (TextView) findViewById(R.id.textView1);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FarshidABZ
Solution 2 Dasser Basyouni