title: Null when passing the context
body: <p>In my dialog, I have a button that I can click on (class: <code>Dialog</code>). Once clicking on that button, the method <code>customTts()</code> (which is in <code>MainActivity</code> class) will be called:</p>
  <pre class="lang-java prettyprint-override"><code>@RequiresApi(api = Build.VERSION_CODES.KITKAT)
  public void CustomTts(String input) throws Exception {
      Tts tts = new Tts(MainActivity.this, _mediaPlayer, barTop, barBottom);
      tts.say(&quot;Hello!&quot;);
  }
  </code></pre>
  <p>The error that I get is:</p>
  <blockquote>
  <p>W/System.err: java.lang.NullPointerException: Attempt to invoke
  virtual method 'android.content.res.Resources
  android.content.Context.getResources()' on a null object reference</p>
  </blockquote>
  <p>The first parameter of <code>Tts()</code> expects <code>Context</code>. So it seems like <code>MainActivity.this</code> returns <em>null</em>.</p>
  <pre class="lang-java prettyprint-override"><code>public class Tts extends MainActivity {
      public Context context;
      private final MediaPlayer _mediaPlayer;
      private CopyBarVisualizer _barTop;
      private CopyBarVisualizer _barBottom;
  
      public Tts(Context context, MediaPlayer _mediaPlayer, BarVisualizer _barTop, BarVisualizer _barBottom) {
          this.context = context;
          this._mediaPlayer = _mediaPlayer;
          this._barTop = (CopyBarVisualizer) _barTop;
          this._barBottom = (CopyBarVisualizer) _barBottom;
      }
  
      @SuppressLint({&quot;NewApi&quot;, &quot;ResourceType&quot;, &quot;UseCompatLoadingForColorStateLists&quot;})
      @RequiresApi(api = Build.VERSION_CODES.KITKAT)
      public void say(String text) throws Exception {
          InputStream stream = context.getResources().openRawResource(R.raw.credential); // R.raw.credential is credential.json
          GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
          TextToSpeechSettings textToSpeechSettings =
                  TextToSpeechSettings.newBuilder()
                          .setCredentialsProvider(
                                  FixedCredentialsProvider.create(credentials)
                          ).build();
  </code></pre>
  <p>How can I pass the context in that case?</p>