3

I am returning encrypted value from getText() With CharSequence for EditText View.

But occurring IllegalArgumentException: Invalid offset: -1. Valid range is [0, 49] Exception

If I set InputType as a number from XML it's working. Like-

<com.shubham.nbsdk.SecureEditText
    android:id="@+id/xpay_encrypt_edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Enter Text to Encrypt"
    android:inputType="number"/>

But having issue with android:inputType="text"

@Nullable
    @Override
    public Editable getText() {
    CharSequence encryptedText = 
    secureSDKImpl_inner.EncryptText(PlainText.toString());
       return new Editable.Factory().newEditable(encryptedText); 
    }

Log

java.lang.IllegalArgumentException: Invalid offset: -1. Valid range is [0, 49]
    at android.text.method.WordIterator.checkOffsetIsValid(WordIterator.java:384)
    at android.text.method.WordIterator.preceding(WordIterator.java:72)
    at android.widget.SpellChecker$SpellParser.parse(SpellChecker.java:592)
    at android.widget.SpellChecker$SpellParser.parse(SpellChecker.java:517)
    at android.widget.SpellChecker.spellCheck(SpellChecker.java:257)
    at android.widget.Editor.updateSpellCheckSpans(Editor.java:702)
    at android.widget.Editor.sendOnTextChanged(Editor.java:1248)
    at android.widget.TextView.sendOnTextChanged(TextView.java:9407)
    at android.widget.TextView.handleTextChanged(TextView.java:9490)
    at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:11948)
    at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1258)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:573)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:504)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:502)
    at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:843)
    at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:616)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:396)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6694)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:769)

I think I am doing something wrong with this

return new Editable.Factory().newEditable(encryptedText);

Any other option to convert CharSequence into Editable

Dor
  • 657
  • 1
  • 5
  • 11
  • Please check here https://stackoverflow.com/questions/13352531/android-how-can-i-convert-a-string-to-a-editable – Deepak S. Gavkar Aug 27 '19 at 05:37
  • Thanks, Sir But I already tried that link, having the same exception with that too @DeepakS.Gavkar – Shubham Kathe Aug 27 '19 at 05:43
  • Can you post the exception? – Deepak S. Gavkar Aug 27 '19 at 05:51
  • Possible duplicate of [Android How can I Convert a String to a Editable](https://stackoverflow.com/questions/13352531/android-how-can-i-convert-a-string-to-a-editable) – geco17 Aug 27 '19 at 06:02
  • @DeepakS.Gavkar Please Check Exception here... [https://pastebin.com/dFKAD1XV](https://pastebin.com/dFKAD1XV) – Shubham Kathe Aug 27 '19 at 06:08
  • Hi, I been testing this line Editable res = new Editable.Factory().newEditable(charSeq); and it works perfectly, I think your problem is somewhere else. please post your exception log. My guess is that your problem is here secureSDKImpl_inner.EncryptText(PlainText.toString()); i assume that it's give you null when you use text. but we will need more information to help you out – Dor Aug 27 '19 at 06:12
  • @WilliamBurnham Sir, My Question is different I am converting CharSequence into Editable – Shubham Kathe Aug 27 '19 at 06:13
  • @Dor Editable res = new Editable.Factory().newEditable(charSeq); This is also working fine for me too only in case of if i set android:inputType="number" from XML. but having issue with `android:inputType="text" – Shubham Kathe Aug 27 '19 at 06:16
  • As i said, your problem is here CharSequence encryptedText = secureSDKImpl_inner.EncryptText(PlainText.toString()); But i need more information to help... please post your error log – Dor Aug 27 '19 at 06:17
  • @ Dor Please Check Log here. https://pastebin.com/dFKAD1XV – Shubham Kathe Aug 27 '19 at 06:19
  • Can't when i click on the link it say "This page is no longer available. It has either expired, been removed by its creator, or removed by one of the Pastebin staff. " just edit your post and add the log – Dor Aug 27 '19 at 06:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198508/discussion-between-shubham-kathe-and-dor). – Shubham Kathe Aug 27 '19 at 06:20
  • The problem is with the line before you create your `Editable`. This works fine because `String` implements `CharSequence`. `CharSequence sequence = "whatever"; Editable editable = Editable.Factory.getInstance() .newEditable(sequence);` What kind of `CharSequence` implementation does your encryption tool give you? Look at the source for `WordIterator#isValidOffset(int)` – geco17 Aug 27 '19 at 17:39

0 Answers0