3

Alright, this is my code:

final TextToSpeech ttv = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() { public void onInit(int status) { ttv.setLanguage(Locale.US); Log.e("Init", "Success"); ttvInit = true; // wait a little for the initialization to complete Handler h = new Handler(); h.postDelayed(new Runnable() { public void run() { ttv.speak(textSpeech.getText().toString(),TextToSpeech.QUEUE_FLUSH,null); } }, 400);} else { System.out.println("Something went wrong."); } } 

but i'm getting an error "Cannot resolve method 'postDelayed(java.lung.Runnable, int)'

EDIT: it's telling me now that it's unused: http://www.igreklik.com/slike/viewer.php?file=75221279105193055086.png&file_imgur=HPjDlfa.png

2 Answers 2

14

Check your import for:

import android.os.Handler; 

and change your code to this (your "else" statement is incorrect):

final TextToSpeech ttv = new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() { public void onInit(int status) { ttv.setLanguage(Locale.US); Log.e("Init", "Success"); ttvInit = true; // wait a little for the initialization to complete Handler h = new Handler(); h.postDelayed(new Runnable() { public void run() { ttv.speak(textSpeech.getText().toString(),TextToSpeech.QUEUE_FLUSH,null); } }, 400); } }); 
Sign up to request clarification or add additional context in comments.

2 Comments

one '}' was missing and i added it, then i got error that ')' and ';' is missing, and i added them as well, but now this is the error: "Error:(35, 9) error: <anonymous cannon.gaming.physicsdroid.MainActivity$1> is not abstract and does not override abstract method onInit(int) in OnInitListener". I edited my post, so you can see how my code looks now
now i deleted the one ttv = new line because i had 2, but now it says the whole thing is unused
0

I just realize that there is a also a class named "Handler" from java.util.logging. You probably import the wrong one as me. Delete it and import android.os.Handler instead.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.