Reputation: 417
I have no idea to why I am recieving this error. With all the example I've seen with the class TimerTask
, this should not cause a problem.
public class CountUp extends AppCompatActivity {
EditText upText = (EditText) findViewById(R.id.Up);
int counter = 0;
float StartTime = 0;
float OffsetTime = 1000; //Offset time is the time between event. 1000 is going to be our milliseconds (1 second)
TimerTask tt = new TimerTask() {
@Override
public void run() {
upText.setText(counter);
counter++;
}
};
public void CountUp(View view){
try {
Timer timer = new Timer();
timer.scheduleAtFixedRate(tt,StartTime,OffsetTime); <--- //This is were I am receiving an error
}catch (Exception e){
}
}
Upvotes: 0
Views: 4191
Reputation: 6707
Replace your whole code with this one:
public class CountUp extends AppCompatActivity {
EditText upText;
TimerTask tt;
int counter = 0;
//startTime and offsetTime must be long and not float.
long startTime = 0;
long offsetTime = 1000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Change this to your current layout.
setContentView(R.layout.main_activity);
upText = (EditText) findViewById(R.id.Up);
tt = new TimerTask() {
@Override
public void run() {
upText.setText(String.valueOf(counter));
counter++;
}
};
}
public void countUp(View view) {
try {
Timer timer = new Timer();
timer.scheduleAtFixedRate(tt, startTime, offsetTime);
} catch (Exception e) {
}
}
}
Upvotes: 3