I'm trying to start an Android notification service with TimerTask but it returns me the following error:
02-03 16:06:00.164 15051-15379/com.celiogarcia.setapp E/AndroidRuntime﹕ FATAL EXCEPTION: Timer-0
java.lang.NullPointerException
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:3845)
at com.celiogarcia.setapp.Sentado$RingNotification.run(Sentado.java:70)
at java.util.Timer$TimerImpl.run(Timer.java:284)
Here's my code ... Maybe you can see what's dark for me ...
public class Sentado extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sentado);
...
}
});
}
public class RingNotification extends TimerTask {
@Override
public void run() {
startService(new Intent(Sentado.this, NotificationService.class));
}
}
public void setTimer(){
Timer timer = new Timer();
TimerTask ringNotify = new RingNotification();
timer.scheduleAtFixedRate(ringNotify, 60000, 60000);
}
}