• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Unable to pause activity : java.lang.NullPointerException: Service not registered: null object refer  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything works fine in my app but when I press the back button (I mean exit app) the app is crashing. And I don't know why? I tried a couple of solutions but nothing works. It's a sounds/ringtones application.


Here my code




And this is my error logs.





How should I resolve this error? Any help would be great. Thanks.

 
Saloon Keeper
Posts: 5478
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe cleanupMediaPlayer has already been called? Either way, calling a method on a null object reference will cause this, so check that mp is not null before calling the method.
 
brahm taci
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Maybe cleanupMediaPlayer has already been called? Either way, calling a method on a null object reference will cause this, so check that mp is not null before calling the method.



Hi Tim

Thanks for your kindly respond. I am new at android, so if you know the solution can you tell me like "add this/delete this"

If you don't know thanks anyway
 
Tim Moores
Saloon Keeper
Posts: 5478
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if nothing else, guard "mp.stop()" by "if (mp != null)".
 
Master Rancher
Posts: 4076
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is line 110 necessary?
I'm always a bit dubious about setting a reference to null.
In this case (based on when cleanUpMediaPlayer is called) it doesn't actually achieve anything, unless some external class calls it?
And if no external class uses that method then it ought to be private.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!