Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8989747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:20:14+00:00 2026-06-15T22:20:14+00:00

I am having problems playing a ringtone on my Nexus 4 running Android 4.2.

  • 0

I am having problems playing a ringtone on my Nexus 4 running Android 4.2.

When I try and play a RingTone I see the following exception:

java.lang.NullPointerException at android.media.Ringtone.play(Ringtone.java:228)

My code is below:

RingtoneManager ringtoneManager = new RingtoneManager(context);
ringtoneManager.setType(AudioManager.STREAM_NOTIFICATION);
Ringtone ringtone = ringtoneManager.getRingtone(index);
Ringtone ringtone.setStreamType(AudioManager.STREAM_NOTIFICATION);

if (ringtone != null)
{
    ringtone.play();
}

The index value is passed into my method based on a user selection (I present them with the list of ringtones to select). In any case it makes no difference what I set this to the behaviour is always the same.

This code works perfectly when running on my two other devices running 2.3 and 4.0.4.

When I debug I can see that the uri is null in the Ringtone that is returned by the ringtone manager (and is set to a valid value on my other devices).

Am I doing something wrong or could this be a bug in 4.2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:20:16+00:00Added an answer on June 15, 2026 at 10:20 pm

    I guess you need to check first if the ringtone exists at the position.
    So try

    Edit: try this.

    RingtoneManager ringtoneManager = new RingtoneManager(ActivityName.this);
    ringtoneManager.setType(AudioManager.STREAM_NOTIFICATION);
    Cursor c = ringtoneManager.getCursor();
    Ringtone ringtone = ringtoneManager.getRingtone(index);
    ringtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
    if(ringtone != null && ringtoneManager.getRingtoneUri(position) != null){    
        ringtone.play();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems playing sounds with MediaPlayer. If the sound starts when the volume
I'm having problems with this code, and the PHP method 'substr' is playing up.
I am having the following problem when playing sounds on the blackberry: The first
still having problems - if I get my code to play the selected audio
I'm having trouble playing a certain .3gp file (from a Dropbox link) with Android's
Im playing around with web.py as a lightweight web framework. Im having problems when
I have been playing around with post-mortem debugging and am having some problems. Consider
I'm having some problems on our fairly busy Windows 2008 R2 web server, running
On Android, I'm having a problem trying to figure out which ringtone is actually
I'm having some problems to start playing an external video file at determinate time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.