简体   繁体   English

java.lang.IllegalStateException:无法对未密封的实例执行此操作

[英]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.

相关问题 “无法在未密封的实例上执行此操作”java.lang.IllegalStateException异常 - “Cannot perform this action on a not sealed instance” java.lang.IllegalStateException exception “java.lang.IllegalStateException:无法对密封实例执行此操作。” 致命例外:主要 - "java.lang.IllegalStateException: Cannot perform this action on a sealed instance." FATAL EXCEPTION: main java.lang.IllegalStateException-在onSaveInstanceState之后无法执行此操作 - java.lang.IllegalStateException - Can not perform this action after onSaveInstanceState java.lang.IllegalStateException(在onSaveInstanceState之后无法执行此操作) - java.lang.IllegalStateException(Can not perform this action after onSaveInstanceState) java.lang.IllegalStateException:使用DialogFragment在onSaveInstanceState之后无法执行此操作 - java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState with DialogFragment 由 java.lang.IllegalStateException 引起 onSaveInstanceState 后无法执行此操作 - Caused by java.lang.IllegalStateException Can not perform this action after onSaveInstanceState java.lang.IllegalStateException: 在 onSaveInstanceState 之后无法执行此操作 - java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState 异常java.lang.IllegalStateException:onSaveInstanceState之后无法执行此操作 - Exception java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState java.lang.IllegalStateException:onSaveInstanceState之后无法执行此操作 - java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState java.lang.IllegalStateException:onSaveInstanceState,FragmentTabHost之后无法执行此操作 - java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState,FragmentTabHost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM