Android Question Crash on clicking selected CSBuilder text in EditText

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have a simple EditText that has a CSBuilder text in it (for SQL syntax highlighting). When I select a length of text (with the normal standard long click) and then do a click within that text I get a crash with this error message:

java.lang.IndexOutOfBoundsException: getChars (-1 ... 527) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:1191)
at android.text.TextUtils.getChars(TextUtils.java:98)
at android.text.TextUtils.substring(TextUtils.java:289)
at android.view.inputmethod.BaseInputConnection.getSelectedText(BaseInputConnection.java:532)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:286)
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:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

The problem is that I can't find where this error originates from. Running in debug mode does cause the same crash but it doesn't point to any B4A line. I tried stepping in debug mode by adding a Click event sub:

B4X:
Sub edtSQL_Click()
    Log("edtSQL_Click")
End Sub

But that doesn't lead me to the origin of the error either.

In case it matters the CSBuilder text does have clickable words, but the error also happens when clicking outside these clickable words. If formatting is turned off, so if the EditText holds plain text
then there is no error.

I am using the latest version of B4A and also the latest Android version.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
No error happens here. My guess is that you are hitting an OS bug. Might be related to the manufacturer theme.

Thanks, that is helpful.
Do you agree that we can now safely say that there is nothing wrong with the CSBuilder?
The phone I tested on is a Samsung S9. Anybody on this forum willing to test this on that particular model?
Will test on my old S7, which was dumped on my wife.

RBS
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
For my app automatic test in Google Console shows for some phones
B4X:
java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 2
   at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1094)
   at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:669)
   at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:662)
   at android.text.Selection.setSelection(Selection.java:123)
   at android.text.Selection.setSelection(Selection.java:134)
   at android.widget.EditText.setSelection(EditText.java:130)
   at android.widget.EditText.performAccessibilityActionInternal(EditText.java:182)
   at android.view.View.performAccessibilityAction(View.java:9473)
   at android.view.AccessibilityInteractionController.performAccessibilityActionUiThread(AccessibilityInteractionController.java:802)
   at android.view.AccessibilityInteractionController.access$500(AccessibilityInteractionController.java:56)
   at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1337)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:158)
   at android.app.ActivityThread.main(ActivityThread.java:7230)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
This happens exactly in first activity (Login). Of course, automatic test can't enter correct login/password.
There is one label with CSBuilder (clickable) only.

I tried to reproduce an error by manual actions. Impossible. From one side this is a positive (users also will not receive an error).
But from another side, no wish to see errors in Google Console.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I don't think that it is related to an issue in CSBuilder. CSBuilder is quite mature and this error was never reported before.
With that said, surprises could always happen.

Just to say that I have tested the little error demo app on my wife's Samsung S7 and no problem at all, so no crash on clicking selected text.
So, happy now this is a particular problem with the Samsung S9.
Would there be any solution for this?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Just to say that I have tested the little error demo app on my wife's Samsung S7 and no problem at all, so no crash on clicking selected text.
So, happy now this is a particular problem with the Samsung S9.
Would there be any solution for this?

RBS

Sorry, spoke to soon.
I tested in debug mode and then all was fine, but in release mode I get exactly the same error on the S7:

--------- beginning of crash
java.lang.IndexOutOfBoundsException: getChars (-1 ... 43) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:1191)
at android.text.TextUtils.getChars(TextUtils.java:98)
at android.text.TextUtils.substring(TextUtils.java:289)
at android.view.inputmethod.BaseInputConnection.getSelectedText(BaseInputConnection.java:532)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:286)
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:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

RBS
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…