Reputation: 2340
I've created a timer that will accept a specified time value from user through edittext box and pass to the CountDownTimer(). This method expect a long value thats why i converted it into long but when i add this long convertion the android emulator shows an error unfortunately stopped.And here is my code
EditText ti=(EditText)findViewById(R.id.time);
Editable i = ti.getText();
String p=i.toString();
long x=Long.parseLong(p);
final TextView mCounter1TextField=(TextView)findViewById(R.id.counter1);
final CountDownTimer Counter1 = new CountDownTimer(x, 10) {
public void onTick(long millisUntilFinished) {
mCounter1TextField.setText(" " + (millisUntilFinished)/ 1000 + ":");
}
public void onFinish() {
mp3.start ();
Log.d ("Splash", "LauncherActivity.onCreate - created MediaPlayer");
cancel();
}
};
//Start Button1
btnstart.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Counter1.start();
}
};
Upvotes: 3
Views: 812
Reputation: 1377
You are trying to convert a string to an integer, i hope. First convert it to an int and then make it long.
Upvotes: 0
Reputation: 29265
Without an error to go on, the first thing I noticed is that you aren't catching a NumberFormatException on parseLong()
long x=0L;
try {
x = Long.parseLong(p);
}
catch(NumberFormatException ex) {
// TODO: error report or something
}
Upvotes: 3