Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – App is crashing Caused by: java.lang.IllegalStateException: No successful match so far

Posted on November 14, 2022

Solution 1 :

Turn minifyenabled back to false has solved the problem.

Problem :

My app is running perfectly at debug mode but is crashing at release mode, so when i set debuggable to be true i realized that the error is from switch case and one method.

Caused by: java.lang.IllegalStateException: No successful match so far
at com.example.speakingtranslator.MainActivity.p(:3334)
at com.example.speakingtranslator.MainActivity$e.onClick(:228)
at android.view.View.performClick(View.java:7043)
at com.google.android.material.button.MaterialButton.performClick(:992)
at android.view.View.performClickInternal(View.java:7016)
at android.view.View.access$3200(View.java:783)
at android.view.View$PerformClick.run(View.java:26595)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6758)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912)
Caused by: java.lang.IllegalStateException: No successful match so far

here is my code

default:
    if (checkInternetConnection()) {
     getTranslateService();
     result = translate();
    } else {
     result = getResources().getString(R.string.no_connection);
    }
   break;
   editTranslate.setText(result);

And here are the methods

public void getTranslateService() {

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        try (InputStream is = getResources().openRawResource(R.raw.credentials)) {

            //Get credentials:
            final GoogleCredentials myCredentials = GoogleCredentials.fromStream(is);

            //Set credentials and get translate service:
            TranslateOptions translateOptions = TranslateOptions.newBuilder().setCredentials(myCredentials).build();
            translate = translateOptions.getService();

        } catch (IOException ioe) {
            ioe.printStackTrace();

        }
    }

    public String translate() {
        originalText = editText.getText().toString();
        Translation translation = translate.translate(originalText, Translate.TranslateOption.targetLanguage("yo"), Translate.TranslateOption.model("nmt"));
        translatedText = translation.getTranslatedText();

        //Translated text and original text are set to TextViews:
        return translatedText;

    }

Here is the full code of OnClickListener of the translate button,i have set of words that i don’t want to bother to send them to the server, that’s why I’m using switch case to test for them, so if the enterred value is not from the list then it should send the word to the api for translation.

trans.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        String t = editText.getText().toString().toLowerCase().trim();

        if (t.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Text Value", Toast.LENGTH_LONG).show();
            editText.requestFocus();
            return;
        }

        String result;

        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setMessage("Please wait while loading..."); // Setting Message
        progressDialog.setTitle("Translating"); // Setting Title
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // Progress Dialog Style Spinner
        progressDialog.setCancelable(true);
        progressDialog.show();

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                progressDialog.dismiss();
            }}, 2000);

        switch (t) {
            case "i love you":
                result = "Mo nif̣ẹrẹ";
                break;
            case "i want you":
                result = "Mo fẹ̣ ọ";
                break;
            case "good evening":
                result = "Ẹ kaalẹ";
                break;
            case "i like you":
                result = "Mo fẹran rẹ";
                break;
            case "how are you":
                result = "Bawo lo se wa";
                break;
            case "i need your help":
                result = "Mo nilo iranlọwọ re";
                break;
            case "i need money":
                result = "Mo nilo owo";
                break;
            case "i miss you":
                result = "Aro rẹ nsọ mi";
                break;
            case "what is my name":
                result = "Kini orukọ mi";
                break;
            case "i love my husband":
                result = "Mo niifẹ ọkọ mi";
                break;
            case "i am hungry":
                result = "Ebi n pa mi";
                break;
            case "i want hot water":
                result = "Mo fẹ omi gbona";
                break;
            case "look at me":
                result = "Wo mi";
                break;
            case "come back":
                result = "Pada wa";
                break;
            case "it is very good":
                result = "O dara pupọ";
                break;
            case "come to school":
                result = "Wa si ile-iwe";
                break;
            case "help yourself":
                result = "Ran ara rẹ lọwọ";
                break;
            case "wait for me":
                result = "Duro de mi";
                break;
            default:
                if (checkInternetConnection()) {
                    getTranslateService();
                    result = translate();
                } else {
                    result = getResources().getString(R.string.no_connection);
                }
            break;
        }
        editTranslate.setText(result);
    }

});

Comments

Comment posted by Jyotish Biswas

Do you using` Matcher` to match any regular expression ?

READ  [ANSWERED] android - how to make localtime.now a continuous function that updates automatically?
Powered by Inline Related Posts

Comment posted by Olizy

No, only switch case to determine to given string value

Comment posted by Jyotish Biswas

please add that portion of code

Comment posted by Olizy

I have updated the question with the full code of onclickListener of the button that will trigger the translation.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress