0

Thanks for seeing my question. My problem is that TextToSpeech(this, this); does not work.

I have initiated it in my code like this.

private TextToSpeech txt2Speech;

then inside onCreate()

    txt2Speech = new TextToSpeech(this, this);

And the end of my code I have declared an onInitListener() like this:

public void onInit(int status) {
    // TODO Auto-generated method stub

}

Yet Android Studio shows an error on this line -

    txt2Speech = new TextToSpeech(this, this);

Saying that

required type onInitListener() does not match the type of my class which is MainActivity.java

What Have I Done Wrong? Pls Help me. Thank you in Advance

KISHORE_ZE
  • 1,466
  • 3
  • 16
  • 26
  • Does your activity implement `TextToSpeech.OnInitListener`? – Andrew Brooke Dec 24 '15 at 20:47
  • Oh! Sorry it's getting pretty late here. I have shut down the computer – KISHORE_ZE Dec 24 '15 at 20:57
  • 1
    But I think u are correct. This has happened before and I think this is the solution. The problem was that it was long back and I didn't remember. Pls post this as an answer. Tomorrow after I have checked it I'll mark it right. And thank you again. – KISHORE_ZE Dec 24 '15 at 20:58

1 Answers1

3

Make sure your Activity implements TextToSpeech.OnInitListener, something like this

public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener

from there you are free to override the onInit method

@Override
public void onInit(int status) {
     // your code
}
Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55