The int function says there is no putExtra... (android studio)

Asked 2 years ago, Updated 2 years ago, 102 views

Intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); Intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); Intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hi speak something"); As a result of using the code, putExtra was underlined in red and an error mark appeared below each.

non-static method putExtra(String,String) cannot be referenced from a static context non-static method putExtra(String,Serializable) cannot be referenced from a static context non-static method putExtra(String,String) cannot be referenced from a static context

So when I rewrite it, it's usually put- If I write it like this, there should be various functions below, but there's nothing that pops up like there's nothing.

It's my first time making it, do I have to download the function separately? Or is there another problem?

intent

2022-09-20 19:47

1 Answers

Intent i = new Intent();
i.putExtra(...)

Please create and use an instance.

Question Author. I'm posting here because I don't know how to post additional questions about the answers.

private void speak() {

    Intent intent = new Intent (RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    Intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    Intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    Intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hi speak something");

    //start intent
    try {
        // // in there was no error
        startActivityForResult(intent, REQUEST_CODE_SPEECH_INPUT);
    }
    catch (Exception e) {
        //if there was some error
        //get message of error and show
        Toast.makeText(this,""+e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

There was an error when there was already a new one.ㅠ<


2022-09-20 19:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.