Search code examples
androidbuttontextviewforceclose

How can I change textview text here


Fibonacci series program which gives next number on button click. I wanted the TextView to give values (ax) of the numbers which are added .

public void next(View v) {
    TextView ax = new TextView(this); //new
    Button next = (Button) findViewById(R.id.next);
    z = x + y;
    next.setText(String.valueOf(z));
    ax.setText(x); //new
    x = y;
    y = z;
}

After adding the "new" lines, the program force closes after button click.


Solution

  • Simple Error

    ax.setText(String.valueOf(x));