Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: Cannot perform this action on a not sealed instance

I am using accessibility service to find a button on screen and click it, but for some reason I am getting the follow error:

java.lang.IllegalStateException: Cannot perform this action on a not sealed instance.
    at android.view.accessibility.AccessibilityNodeInfo.enforceSealed(AccessibilityNodeInfo.java:3046)
    at android.view.accessibility.AccessibilityNodeInfo.findAccessibilityNodeInfosByText(AccessibilityNodeInfo.java:1529)
    at com.myapp.adapters.Adapter_Click$11.run(Adapter_Click.java:1874)
    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:6718)
    at java.lang.reflect.Method.invoke(Method.java:-2)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

And the line that it refers to is:

List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByText("Accept".toLowerCase());

And then I use this to click the button:

if (view.performAction(AccessibilityNodeInfo.ACTION_CLICK)) 
{
  Log.e(TAG, "Button clicked");
}

I didn't see any issues with this for the last year until I just recently updated to AndroidX. Is there a way to check if it is a sealed instance before trying to click it? I even tried to wrap it in a try/catch and it still crashes my app.

like image 390
user2101081 Avatar asked Feb 23 '19 16:02

user2101081


1 Answers

(It's kind of a pain, but if a node gets ditched most functionality on it breaks horribly -- even refresh(). It's strange, since as far as I know you're allowed to retain instances as long as you need them.)

You can easily check if one is still valid by checking if getClassName() returns null -- if it does, drop it like a hot potato! You can't do anything with it anymore -- don't even recycle() it because something already did that underneath your feet.

like image 85
Keilaron Avatar answered Oct 28 '22 18:10

Keilaron