0

I'm trying to use the texttospeech library, however I get error "

cannot find symbol
symbol  : constructor TextToSpeech(com.example.android.animationsdemo.MainActivity,com.example.android.animationsdemo.MainActivity)

It's not the first time I've gotten this error, but I don't understand what it means. What do this error message mean? And how can I fix these errors?

This is my code up to the line with the error:

package com.example.android.animationsdemo;

import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.speech.tts.TextToSpeech;
import android.app.Activity;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends FragmentActivity {\
    private TextToSpeech talker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        talker = new TextToSpeech(this, this);
lisovaccaro
  • 32,502
  • 98
  • 258
  • 410

1 Answers1

2

Based on API reference, the constructor accepts Context and TextToSpeech.OnInitListener. However, your activity doesn't implement TextToSpeech.OnInitListener.

You have 3 alternatives: make your activity implement the listener, create a named listener, or create an anonymous listener. However, based on your current code, I'll recommend the first approach.

public class MainActivity extends FragmentActivity
  implements TextToSpeech.OnInitListener {

    ....

    @Override
    public void onInit (int status){
        // implement the listener here
    }
}
Andrew T.
  • 4,701
  • 8
  • 43
  • 62