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 7762191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:20:00+00:00 2026-06-01T14:20:00+00:00

I am getting a null pointer exception report in the android developer console. I

  • 0

I am getting a null pointer exception report in the android developer console. I need some advise as to what possibly is the problem here, the stack trace is like this

java.lang.NullPointerException
at com.myfreeapp.workers.Speaker.onInit(Speaker.java:57)
at android.speech.tts.TextToSpeech$1.onServiceConnected(TextToSpeech.java:451)
at android.app.ActivityThread$PackageInfo$ServiceDispatcher.doConnected(ActivityThread.java:1247)
at android.app.ActivityThread$PackageInfo$ServiceDispatcher$RunConnection.run(ActivityThread.java:1264)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4668)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)

The relevant code snippet in my app is

public Speaker(final Context context, final Settings settings) 
{   
    this.settings = settings;
    params = new HashMap<String, String>();      
    params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "myfreeapps");

    tts= new TextToSpeech(context, this);   
    Utils.log(TAG, "Created TextToSpeech..");
}

@Override
public void onInit(final int status) 
{
    Utils.log(TAG, "TTS onInit..");

//below is line 57 mentioned in the stack trace
    tts.setOnUtteranceCompletedListener(new SpeechFinishedListener());
    tts.setLanguage(Locale.getDefault());
    tts.setSpeechRate(settings.getSpeed());
    tts.setPitch(settings.getPitch());      
    ready = true;

}

Please first of all I need to be clear what exactly is null..
Is the stack trace pointing to variable tts on line 57 to be null..?

Or is the null pointer exception happening inside the TextToSpeech method setOnUtteranceCompletedListener ?

The Speaker instance is created on the main thread in a sticky service, and when I debug my code the callback from TextToSpeech also comes back on the same thread..

I don’t understand how could the variable tts be null ???

By the way this problem is not reproducible on my end. I have this stack strace reported several times on the developer console.

Please advise,

  • 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-01T14:20:02+00:00Added an answer on June 1, 2026 at 2:20 pm

    I resolved the problem, here is how it worked

    There was a case where I was creating Speaker object on a non-ui thread.
    The callback to onInit() would come on UI thread/main thread..

    now even though running it might not always crash but I realised it was not safe and chances of null pointer exceptions are there..

    so my updated code looks like this

    public Speaker(final Context context, final Settings settings) 
    {   
        this.settings = settings;
        params = new HashMap<String, String>();      
        params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "myfreeapps");
    
        synchronize(synchobject)
        {
           tts= new TextToSpeech(context, this);   
        }
        Utils.log(TAG, "Created TextToSpeech..");
    }
    
    @Override
    public void onInit(final int status) 
    {
        Utils.log(TAG, "TTS onInit..");
    
        synchronize(synchobject)
        {
    
        tts.setOnUtteranceCompletedListener(new SpeechFinishedListener());
        tts.setLanguage(Locale.getDefault());
        tts.setSpeechRate(settings.getSpeed());
        tts.setPitch(settings.getPitch());      
        ready = true;
        }
    
    }
    

    This seems to have resolve my problem , thanks every one for your contribution to help me out,..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam getting a null pointer exception while sending some string text as an sms
Hi i am reading inbox using service but i m getting null pointer exception
I am getting null pointer exception while trying to add anything in my solrQueue.
Hoping you guys can figure out why im getting a null pointer exception with
Im getting null pointer exception in unbindDrawables where im Removing callbacks on all the
I am getting null pointer exception when I am trying to get lat/long from
I am getting Null Pointer Exception for ImageView imag = (ImageView) findViewById(R.id.image). I have
I am getting null pointer exception, due to failed to recognize layout parameter in
I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).
Below is the code I am trying to test, but getting null pointer exception

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.