1
I am trying to start an Android notification service with Timertask but 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 is my code ... Maybe you can see what is dark to 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);
}
}
Put all the generated stacktrace to facilitate the identification of the problem.
– André Ribeiro
@Andréribeiro made...
– user2647038
I believe the error is in "context" but the truth is that I see no other way to pass the parameter ...
– user2647038
Is this an Android app? Why are you using the method
public static void main
?– ramaral
Yes. In this example I used this method to simplify the explanation of my problem, by background, the result you give in this example, is even that I will have in my project...
– user2647038
What is the class
Sentado
?– ramaral
It’s the class Mother....
– user2647038
But what is your type? It’s Activity or other?
– ramaral
É uma Activity ...
– user2647038