• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7600
177
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7600
177
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if nothing else, guard "mp.stop()" by "if (mp != null)".
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic