title: 'android.content.res.Resources android.content.Context.getResources()' on a null object reference. Converting String array to speech
body: <p>I'm developing an app in which I've Display strings and I've got a String Array. I want to <strong>convert String Array text to speech</strong>. But I'm having this error.
  I'm giving index to the String array so it can get converted it into speech on OnDone UtteranceProgressListener().</p>
  
  <p>here's my code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {
  TextView textView;
  Button button;
  private boolean initialized;
  private String[] queuedText;
  private String TAG = "TTS";
  private TextToSpeech tts;
  int i = 0;
  
  
  String[] Story = getResources().getStringArray(R.array.Storytxt);
  
  String ajay = ("Once, a wolf was very hungry. It looked for food here and there. But it couldn't get any. At last, it found a loaf of bread and piece of meat in the hole of a tree.\n" +
          "\n" +
          "The hungry wolf squeezed into the hole. It ate all the food. It was a woodcutter's lunch. He was on his way back to the tree to have lunch. But he saw there was no food in the hole, instead, a wolf.\n" +
          "\n" +
          "On seeing the woodcutter, the wolf tried to get out of the hole. But it couldn't. Its tummy was swollen.\n" +
          "\n" +
          "The woodcutter caught the wolf and gave it nice beatings.");
  
   @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      textView = findViewById(R.id.highlightxt);
      textView.setText(ajay);
      button = findViewById(R.id.button);
  
      tts = new TextToSpeech(getApplicationContext() /* context */, this /* listener */);
  
      tts.setOnUtteranceProgressListener(mProgressListener);
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              speak(Story,i);
          }
      });
  }
  
  private void speak(String[] text, int i) {
      i = 0;
  
      if(!initialized){
          queuedText[i] = text[i];
          return;
      }
      queuedText = null;
      setTtsListner();
      HashMap&lt;String , String&gt; map = new HashMap&lt;String, String&gt;();
      map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"Message ID");
      tts.speak(text[i],TextToSpeech.QUEUE_ADD, map);
  
  }
  
  private void setTtsListner() {
  }
  
  @Override
  public void onInit(int status) {
      if (status == TextToSpeech.SUCCESS) {
          initialized = true;
          tts.setLanguage(Locale.ENGLISH);
  
          if (queuedText != null) {
              speak(queuedText,i);
          }
      }
  }
  private abstract class runnable implements Runnable {
  }
      private UtteranceProgressListener mProgressListener = new UtteranceProgressListener() {
          @Override
          public void onStart(String utteranceId) {
          } // Do nothing
  
          @Override
          public void onError(String utteranceId) {
          } // Do nothing.
  
          @Override
          public void onDone(String utteranceId) {
  
              new Thread() {
                  public void run() {
                      MainActivity.this.runOnUiThread(new runnable() {
                          public void run() {
  
                              Toast.makeText(getBaseContext(), "TTS Completed", Toast.LENGTH_SHORT).show();
                          }
                      });
                  }
              }.start();
              i = i+1;
              speak(Story, i);
          }
      };
  </code></pre>
  
  <p>}</p>
  
  <p>I'm having this error.</p>
  
  <pre><code>    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gujja.ajay.texthight/com.gujja.ajay.texthight.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
  </code></pre>
  
  <p>I don't know why I'm getting this. is this bcoz of the String array?</p>
  
  <pre><code>&lt;string-array name="Storytxt"&gt;
  
      &lt;item&gt;Once, a wolf was very hungry. It looked for food here and there. But it couldn\'t get any. At last it found a loaf of bread and piece of meat in the hole of a tree.&lt;/item&gt;
      &lt;item&gt;The hungry wolf squeezed into the hole. It ate all the food. It was a woodcutter\'s lunch. He was on his way back to the tree to have lunch. But he saw there was no food in the hole, instead, a wolf.&lt;/item&gt;
      &lt;item&gt;On seeing the woodcutter, the wolf tried to get out of the hole. But it couldn\'t. Its tummy was swollen.&lt;/item&gt;
      &lt;item&gt;The woodcutter caught the wolf and gave it nice beatings.&lt;/item&gt;
  
  &lt;/string-array&gt;
  </code></pre>