java


Service crashes on app close


I am building an app to remind me stuff. I am using alarm manager for repeated alarms. But the problem when i set multiple alarms, if i close the app the first alarm service crashes, the second one works fine. I don't know why.
public void setReminder(){
Calendar dm = Calendar.getInstance();
AlarmManager alarmManager = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(activity , broadcast.class);
intent.putExtra("com.todolist.dailylist.data" , listUID);
PendingIntent pendingintent = PendingIntent.getBroadcast(getApplicationContext(),alarmID, intent , PendingIntent.FLAG_ONE_SHOT);
int month = Integer.parseInt(splitDate(date)[1]);
dm.set(Calendar.MONTH, month -1 );
dm.set(Calendar.DAY_OF_MONTH, Integer.parseInt(splitDate(date)[0]));
dm.set(Calendar.YEAR, Integer.parseInt(splitDate(date)[2]));
dm.set(Calendar.HOUR, Integer.parseInt(formatTime(timeVar)[0]));
dm.set(Calendar.MINUTE, Integer.parseInt(formatTime(timeVar)[1]));
if(formatTime(timeVar)[2].equals("AM")) {
dm.set(Calendar.AM_PM, Calendar.AM);
}else if(formatTime(timeVar)[2].equals("PM")){
dm.set(Calendar.AM_PM, Calendar.PM);
}
long when = dm.getTimeInMillis();
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,when, AlarmManager.INTERVAL_DAY ,pendingintent);
}
Broadcast receiver code
public class broadcast extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String intentID = intent.getStringExtra("com.todolist.dailylist.data");
Intent service = new Intent(context, service.class);
service.putExtra("com.todolist.dailylist.listID", intentID);
context.startService(service);
}
}
Service shows a overlay window when the alarm triggers like the most to do apps.
Service class .
public class service extends Service {
private WindowManager windowManager;
private LayoutInflater inflater;
private View myview;
private diUtil databaseutil;
private String listID;
private String value = null;
private TextView listTitle;
private TextView listDescription;
private RelativeLayout rootLayout;
private RelativeLayout controllerIcons;
private ImageButton doneImage;
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
databaseutil = new diUtil(this);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_TOAST,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.CENTER;
myview = inflater.inflate(R.layout.notificationwindow , null);
listTitle = (TextView)myview.findViewById(R.id.listTitleHeader);
listDescription = (TextView)myview.findViewById(R.id.listDescriptionHeader);
controllerIcons = (RelativeLayout)myview.findViewById(R.id.controller_icons);
rootLayout = (RelativeLayout)myview.findViewById(R.id.layout_controller);
doneImage = (ImageButton) myview.findViewById(R.id.doneIconController);
windowManager.addView(myview, params);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
listID = intent.getStringExtra("com.todolist.dailylist.listID");
ArrayList<listData> data = databaseutil.getListitem(listID);
for(int i=0; i < data.size();i++){
listTitle.setText(data.get(i).getListName());
if(data.get(i).getListText() != null){
Toast.makeText(this, "description present", Toast.LENGTH_SHORT).show();
}else if(data.get(i).getListText() == null){
Toast.makeText(this, "description not present", Toast.LENGTH_SHORT).show();
}
doneImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
windowManager.removeView(myview);
}
});
}
return Service.START_STICKY;
}
#Override
public void onDestroy() {
windowManager.removeView(myview);
super.onDestroy();
}
}
Here's the error i got from the logcat console
Process: com.todolist.dailylist, PID: 5601
java.lang.RuntimeException: Unable to start service com.todolist.dailylist.services.service#6a10f79 with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3314)
at android.app.ActivityThread.-wrap21(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1565)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
at com.todolist.dailylist.services.service.onStartCommand(service.java:74)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3297)
at android.app.ActivityThread.-wrap21(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1565) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Anybody knows why this happens and how to solve this issue ?. Thank you so much for reading. Highly appreciated !.

Related Links

Java: get instance of Generic [duplicate]
Help with ISBN Checker written in Java
Applet displays login dialog if basic authentication used
Managing upgrades to Java 7
Store Blob in Heroku (or similar cloud services)
Calling Java Method HttpServletResponse in flex 4
How do I get a JTable header to display entire column names instead of shortening them?
Adapter Threadpool Error with Jboss
How to sort a list of values according to numeric, alpha numeric, aplhabetic and strings with special characters which occur in the same position [duplicate]
using ArrayList for counting
faster way for moving large amounts data in oracle to external database
Using Hibernate for enumerations / type codes
Read the XML attributes in a custom class Android
Java get first and last 2 byte from int var
class constructor cannot be accessed by outside package
Parsing zxing qrcode decode response with php

Categories

HOME
coq
amazon-ec2
reflection
ngrx
kde
cmd
jsrender
frameworks
uber-api
swagger-ui
upload
amazon-cloudformation
volttron
quicklook
remote-access
size
try-catch
lombok
text-rendering
swiftlint
tibco-mdm
icloud-api
facebook-access-token
elasticsearch-net
windows-server-2000
webkitspeechrecognition
react-chartjs
google-cloud-endpoints-v2
fog
mmenu
appfabric
scaffold
android-browser
sqlite2
reportingservices-2005
sage-one
togetherjs
yii2-extension
gcsfuse
pycaffe
pintos
nxt
libpng
savon
trash
ipconfig
rtbkit
intel-fortran
eclipse-clp
security-testing
sframe
sorl-thumbnail
nstableviewcell
camanjs
fpml
socketexception
html-helper
yorick
intentservice
pyhdf
soundtouch
xamlparseexception
interface-orientation
venn-diagram
wse3.0
adk
deobfuscation
joyent
table-footer
netbeans-7.1
nhibernate.search
vc90
meego
ctp4
zune
genealogy
3gp
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App