android – Text to speech, can't use multiple language?-ThrowExceptions

Exception or error:

I would like to know how i can add multiple language for text to speech I don’t really understand the other example as there’s method is different from what I’m typing. And I have no idea what i should be doing to support multiple language for text to speech?

     public class MainActivity extends AppCompatActivity {
     private TextToSpeech textToSpeech;
     private TextView  outputTextView;
     private Intent intent;

    protected void onCreate(Bundle savedInstanceState) {
        Toolbar toolbar = findViewById(;

        FloatingActionButton fab = findViewById(;
        outputTextView = findViewById(;
        outputTextView.setMovementMethod(new ScrollingMovementMethod());

        textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            public void onInit(int status) {

        fab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == {
            return true;

        return super.onOptionsItemSelected(item);
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *