android - Nullpointer at creating PendingIntent -


i nullpointer @ intent alarmintent = new intent(this, mynotification.class); have no idea how fix this.. hope might able me..

what should set alarm everyday @ 9 can set notification in mynotification class contains broadcastreceiver.

below code:

calling alarmmanager class (from mainactivity):

alarm setalarm = new alarm();         setalarm.setrecurringalarm(); 

the class want set alarmmanager (alarm.class):

public class alarm extends activity { public void setrecurringalarm() {      log.i("alarm", "setting recurring alarm");      calendar updatetime = calendar.getinstance();      updatetime.set(calendar.hour, 7);     updatetime.set(calendar.minute, 0);     updatetime.set(calendar.second, 0);      intent alarmintent = new intent(this, mynotification.class);     pendingintent recurringdownload = pendingintent.getbroadcast(this, 0, alarmintent, pendingintent.flag_cancel_current);     alarmmanager alarms = (alarmmanager) getsystemservice(context.alarm_service);     alarms.cancel(recurringdownload);     alarms.setinexactrepeating(alarmmanager.rtc, updatetime.gettimeinmillis(), alarmmanager.interval_day , recurringdownload); } 

}

logcat output:

08-07 22:43:38.079: e/androidruntime(21476): fatal exception: main 08-07 22:43:38.079: e/androidruntime(21476): java.lang.runtimeexception: unable start activity componentinfo{com.weatherclothes/com.weatherclothes.mainactivity}: java.lang.nullpointerexception 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2355) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2391) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activitythread.access$600(activitythread.java:151) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activitythread$h.handlemessage(activitythread.java:1335) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.os.handler.dispatchmessage(handler.java:99) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.os.looper.loop(looper.java:155) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activitythread.main(activitythread.java:5493) 08-07 22:43:38.079: e/androidruntime(21476):    @ java.lang.reflect.method.invokenative(native method) 08-07 22:43:38.079: e/androidruntime(21476):    @ java.lang.reflect.method.invoke(method.java:511) 08-07 22:43:38.079: e/androidruntime(21476):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1028) 08-07 22:43:38.079: e/androidruntime(21476):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:795) 08-07 22:43:38.079: e/androidruntime(21476):    @ dalvik.system.nativestart.main(native method) 08-07 22:43:38.079: e/androidruntime(21476): caused by: java.lang.nullpointerexception 08-07 22:43:38.079: e/androidruntime(21476):    @ android.content.componentname.<init>(componentname.java:75) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.content.intent.<init>(intent.java:3655) 08-07 22:43:38.079: e/androidruntime(21476):    @ com.weatherclothes.alarm.setrecurringalarm(alarm.java:23) 08-07 22:43:38.079: e/androidruntime(21476):    @ com.weatherclothes.mainactivity.oncreate(mainactivity.java:58) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activity.performcreate(activity.java:5066) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1101) 08-07 22:43:38.079: e/androidruntime(21476):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2311) 08-07 22:43:38.079: e/androidruntime(21476):    ... 11 more 

just wondering, why doing way, instead of putting setrecurringalarm() method in mainactivity?

you creating instance of alarm activity, , calling method on it. dont see need in activity.

just guessing, using alarm activity context without being launched causing nullpointerexception.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -