I'm trying to make a really simple timer where it adds 1 every 2 seconds in an EditText:
- Code: Select all
public class timeractivity extends Activity {
Timer timer;
Button b1;
public EditText edittext;
int x = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1 = (Button)findViewById(R.id.Button01);
edittext = (EditText)findViewById(R.id.EditText01);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timer.schedule(new RemindTask(), 2000);
}
});
}
class RemindTask extends TimerTask {
public void run() {
x+=1;
edittext.setText(x);
}
}
}
But when I click on the button I get FC..
Why is this happening?
Thanks