Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.nullpointerexception at android.content.contextwrapper.getsystemservice(Contextwrapper.java:386)
    primarykey
    data
    text
    <p>I'm creating a Notification Service with custom date and time, and I can't do this. I download this code <a href="http://blog.blundell-apps.com/notification-for-a-user-chosen-time/" rel="nofollow">http://blog.blundell-apps.com/notification-for-a-user-chosen-time/</a> and this work fine, but when I include the code in my project don't work.</p> <p>I have this code</p> <pre><code>package com.blundell.tut.service.task; import java.util.Calendar; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.blundell.tut.service.NotifyService; /** * Set an alarm for the date passed into the constructor * When the alarm is raised it will start the NotifyService * * This uses the android build in alarm manager *NOTE* if the phone is turned off this alarm will be cancelled * * This will run on it's own thread. * * @author paul.blundell */ public class AlarmTask implements Runnable{ // The date selected for the alarm private final Calendar date; // The android system alarm manager AlarmManager am; // Your context to retrieve the alarm manager from private final Context contextt; public AlarmTask(Context context, Calendar date) { Log.v("AlarmTask", "AlarmTask"); this.contextt = context; this.am = (AlarmManager) context.getSystemService(contextt.ALARM_SERVICE); this.date = date; } public void run() { Log.v("AlarmTask", "run"); // Request to start are service when the alarm date is upon us // We don't start an activity as we just want to pop up a notification into the system bar not a full activity Intent intent = new Intent(contextt, NotifyService.class); intent.putExtra(NotifyService.INTENT_NOTIFY, true); PendingIntent pendingIntent = PendingIntent.getService(contextt, 0, intent, 0); // Sets an alarm - note this alarm will be lost if the phone is turned off and on again am.set(AlarmManager.RTC, date.getTimeInMillis(), pendingIntent); } } </code></pre> <p>In this line i get a error</p> <pre><code>this.am = (AlarmManager) context.getSystemService(contextt.ALARM_SERVICE); </code></pre> <p>I send de context from this class</p> <pre><code>package com.blundell.tut.service; import java.util.Calendar; import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.IBinder; import android.util.Log; import com.blundell.tut.service.task.AlarmTask; public class ScheduleService extends Service { /** * Class for clients to access */ public class ServiceBinder extends Binder { ScheduleService getService() { return ScheduleService.this; } } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public IBinder onBind(Intent intent) { return mBinder; } // This is the object that receives interactions from clients. See private final IBinder mBinder = new ServiceBinder(); /** * Show an alarm for a certain date when the alarm is called it will pop up a notification */ public void setAlarm(Calendar c) { // This starts a new thread to set the alarm // You want to push off your tasks onto a new thread to free up the UI to carry on responding new AlarmTask(this, c).run(); } } </code></pre> <p>and i get this error</p> <pre><code>java.lang.nullpointerexception at android.content.contextwrapper.getsystemservice(Contextwrapper.java:386) </code></pre> <p>Sorry for my english :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload