• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Trying to make a countdown timer. Some help please

ktUK

Newbie
As a part of my app I would like to include a countdown timer.

I would much rather have the timer count in minutes and seconds, so if anyone knows of a good tutorial to set such a timer up I would rather they point me in that direction first (I have looked)

My problem is that I'm getting this error when I press the button to open the activity

02-27 21:07:47.776: E/AndroidRuntime(711): Uncaught handler: thread main exiting due to uncaught exception
02-27 21:07:47.786: E/AndroidRuntime(711): java.lang.RuntimeException: Unable to start activity ComponentInfo{converter.units.kitchen/converter.units.kitchen.Timer}: java.lang.NullPointerException


I currently have the following java activity


import
android.app.Activity;
import


android.os.Bundle;
import


android.os.CountDownTimer;
import


android.widget.EditText;
import


android.widget.TextView;

public


class Timer extends Activity {

TextView count;
EditText start;

/** Called when the activity is first created. */
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);

count


= new TextView(this);
this.setContentView(count);

start = (EditText)findViewById(R.id.timer1);
int int1 = Integer.parseInt(start.getText().toString());
int startint = int1*1000;


MyCount counter =


new MyCount(startint,1000);

counter.start();

}


publicclass MyCount extends CountDownTimer{

public


MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}

@Override
publicvoid onFinish() {
count.setText("Finish");
}

@Override
publicvoid onTick(long millisUntilFinished) {
count.setText(millisUntilFinished/1000 + "left");

}

}
}






It was working fine when I had a fixed number as the starting value, although since reverting to a fixed number it still does not work.

Thank you very much for your help
 
Ok, so you have 2 problems:

1) You are constructing an EditText but not adding it to the scene.

2) Immediately after constructing the EditText, you are parsing its contents, which at this point will have nothing in it since you haven't given the user a chance to enter anything. That's where your exception comes from.
 
Back
Top Bottom