• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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: 5412
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: 5412
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: 4042
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.
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!