I am getting "android.content.res.Resources$NotFoundException: String resource ID" on code
private void getOTPFromMessage(String message) { Pattern otpPatter = Pattern.compile("(|^)\d{6}");
Matcher matcher = otpPatter.matcher(message);
if (matcher.find()) {
String otp = matcher.group().toString();
System.out.println("otp = " otp);
System.out.println("otp.length() = " otp.length());
etInputOTP1.setText(otp.charAt(0));//this line
etInputOTP2.setText(otp.charAt(1));
etInputOTP3.setText(otp.charAt(2));
etInputOTP4.setText(otp.charAt(3));
etInputOTP5.setText(otp.charAt(6));
etInputOTP6.setText(otp.charAt(5));
}
}
After getting the error application is getting crashed.
can anyone explain me this exception and how to resolve it.
exception trace
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.vedantkakade.liveasytask, PID: 21106
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=Intent { (has extras) }} to activity {com.vedantkakade.liveasytask/com.vedantkakade.liveasytask.VerifyOTP}: android.content.res.Resources$NotFoundException: String resource ID #0x30
at android.app.ActivityThread.deliverResults(ActivityThread.java:5097)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5138)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7807)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x30
at android.content.res.Resources.getText(Resources.java:382)
at android.widget.TextView.setText(TextView.java:6953)
at com.vedantkakade.liveasytask.VerifyOTP.getOTPFromMessage(VerifyOTP.java:94)
at com.vedantkakade.liveasytask.VerifyOTP.onActivityResult(VerifyOTP.java:79)
at android.app.Activity.dispatchActivityResult(Activity.java:8292)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5090)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5138)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7807)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
CodePudding user response:
when you invoke setText('char')
, your'e actually calling the setText function that expects a string resource
id, thats why your'e getting a resource not found exception.
Try to concat it to an empty string
.setText(otp.charAt(0) "")