I have two questions, I took the below code from a tutorial website in the process of trying to learn and find out how to set a countdown timer. But when I started the up in the emulator it crashed before starting and android force closed it.
So here are my two questions:
1-What, or where is the line that caused the error?
2-I put break point on the onCreate method, and switched to the debugger view, and here I couldn’t know how to use the debugger view in Eclipse. Where to look for the faulty error, and why the Eclipse debugger doesn’t highlight the line it is stopping on?
I would love to get answer for the 2nd question more than the first. Obviously 🙂
Thanks to anyone for helping, or trying to help.
public class MytestActivity extends Activity {
/** Called when the activity is first created. */
TextView tv; //textview to display the countdown
//final TextView tv = (TextView) findViewById(R.id.editText1);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//final TextView tv = (TextView) findViewById(R.id.editText1);
tv = new TextView(this);
this.setContentView(tv);
//5000 is the starting number (in milliseconds)
//1000 is the number to count down each time (in milliseconds)
MyCount counter = new MyCount(5000,1000);
counter.start();
}; //end of onCreate class
//countdowntimer is an abstract class, so extend it and fill in methods
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
tv.setText("done!");
}
@Override
public void onTick(long millisUntilFinished) {
tv.setText("Left: " + millisUntilFinished/1000);
}
} //end of MyCount class
} //End of activity class
Log Cat is a much better solution for debugging then the standard debugging techniques. Learning to use it correctly is a big step for a fledgling Android programmer. Here is a handy video that will hopefully get you started: http://www.youtube.com/watch?v=wPaUxCrp6qI