[英]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.去年我没有看到任何问题,直到我最近更新到 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.
我什至尝试将它包装在 try/catch 中,但它仍然使我的应用程序崩溃。
(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.) (这有点痛苦,但如果一个节点被抛弃,它的大部分功能都会严重中断——甚至
refresh()
。这很奇怪,因为据我所知,只要你需要,你就可以保留实例。)
You can easily check if one is still valid by checking if getClassName()
returns null -- if it does, drop it like a hot potato!您可以通过检查
getClassName()
返回 null 来轻松检查它是否仍然有效——如果是,请像烫手山芋一样丢弃它! You can't do anything with it anymore -- don't even recycle()
it because something already did that underneath your feet.你不能再用它做任何事情——甚至不要
recycle()
它,因为已经有东西在你脚下做了。
Sealing is done to make nodes immutable.密封是为了使节点不可变。 These kind of exceptions often come when a service uses a node after it's been recycled.
当服务在回收后使用节点时,通常会出现此类异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.