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 ?
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.