Android Question Debugging a problematic comparison

nwhitfield

Active Member
Licensed User
Longtime User
I'm just pulling together some code examples to put on my website, and a piece of code that was working fine last time I was tinkering with it has now decided to crash.

In debug mode, I can see the logs, and the error reported is

java.lang.IllegalArgumentException: Comparison method violates its general contract!

but for some reason, the IDE doesn't highlight the offending line of code

This, naturally, is making it a bit fiddly to work out exactly where things have gone wrong. Anyone care to suggest any clues?
 

stevel05

Expert
Licensed User
Longtime User
What is the line of code that is reported as failing?
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
That is precisely the problem; I have no idea. Every other time I've had an app crash while testing, the B4A IDE has helpfully highlighted the offending code. Not with this one. All I have is the java error messages, and the "Unfortunately Example1 has stopped" pop up on the phone screen.

It looks like it's possibly to do with java.util.Arrays.sort but since I'm not sorting an array (or even comparing elements, though I am iterating over one), that seems most peculiar. I know I'm not exceeding the bounds
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Sure, Erel:

B4X:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:831)
    at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:449)
    at java.util.ComparableTimSort.mergeForceCollapse(ComparableTimSort.java:388)
    at java.util.ComparableTimSort.sort(ComparableTimSort.java:187)
    at java.util.ComparableTimSort.sort(ComparableTimSort.java:142)
    at java.util.Arrays.sort(Arrays.java:1973)
    at java.util.Collections.sort(Collections.java:1867)
    at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:6492)
    at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:6457)
    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1672)
    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1681)
    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1681)
    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1681)
    at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1681)
    at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal(ViewGroup.java:2507)
    at android.view.View.onInitializeAccessibilityNodeInfo(View.java:4986)
    at android.widget.FrameLayout.onInitializeAccessibilityNodeInfo(FrameLayout.java:584)
    at android.view.View.createAccessibilityNodeInfoInternal(View.java:4947)
    at android.view.View.createAccessibilityNodeInfo(View.java:4934)
    at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:700)
    at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:147)
    at android.view.AccessibilityInteractionController.access$300(AccessibilityInteractionController.java:49)
    at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:961)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
No, I'm not. But you just gave me a flash of inspiration.

This is a simple example for the magazine, using labels that look like blocks to explore logic in the game. So I add a lot of labels to a view, and remove them to refresh the pieces.

It works, but it's not meant to look pretty. At least it worked when I wrote the code. And didn't work now.

Then when you mentioned accessibility I remembered that since then I installed LastPass Premium on my phone, and that has an option to allow it to fill in login dialogs in apps for you, which you enable via the Android accessibility screen. I had that turned on.

I just went into the phone settings and turned that off, and now it works again.

So, nothing wrong with my code. Other than that it was probably confusing the hell out of LastPass!
 
Upvote 0

touchsquid

Active Member
Licensed User
Longtime User
General question. How would one prevent this from causing problems to a user? Is there a way to disable accessibility feature when in a B4A app?
 
Upvote 0

touchsquid

Active Member
Licensed User
Longtime User
I found this in the Android bug forum:

I encountered this issue. It seems that if you are using a ViewGroup (i.e. layout) that has two or more children with the same topleft xy coordinate then you may get the exception. I was using a custom ViewGroup and its children were overlapping in this way. To fix the problem, I overrode this function in my custom ViewGroup:

@override
public void addChildrenForAccessibility(ArrayList<View> c) {}

Does anyone know how to implement this in B4a using JavaObject or Reflection?
 
Upvote 0

touchsquid

Active Member
Licensed User
Longtime User
Do you think it could be done in a library? I'm pretty anxious to solve this problem. It seems a LOT of users have password apps.
 
Upvote 0
Top