For some reason my code gives one random number but crashes after the second due to a null pointer exception. Does anybody know how I can fix this?
public void shownumbers() {
Timer MyTimer = new Timer();
MyTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Random r = new Random();
TextView viewbox = (TextView) findViewById(R.id.textView);
viewbox.setText(Integer.toString(r.nextInt(10)));
}
}, 100, 500);