gpt4 book ai didi

java - Android:来自可运行的异步任务 - “Activity has leaked window that was originally added here”

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:00 27 4
gpt4 key购买 nike

当从可运行对象调用时,我的“doInBackground”似乎不会触发。任何人都可以帮助我的代码吗?

此链接显示了调用后台/可运行任务的一般流程。 (还有我的错误+注释。我还将屏幕截图并发布在下面)lucidchart*com/invitations/accept/1edf5782-b8d5-4ee6-bc37-4eb3bbfe56a9

似乎错误是在尝试处理空文件时发生的,似乎正在执行预执行,其中文件被删除,但 doInBacground 没有执行,文件被重建。

似乎这个问题与Dialogue.show/dismiss有关,这一定是因为“doInBackground”没有运行。

调试时,我在 Async 类中发现了此异常:调试时出现此错误

@MainThread
public final AsyncTask<Params, Progress, Result> executeOnExecutor(Executor exec,
Params... params) {
if (mStatus != Status.PENDING) {
switch (mStatus) {
case RUNNING:
throw new IllegalStateException("Cannot execute task:"
+ " the task is already running.");
case FINISHED:
throw new IllegalStateException("Cannot execute task:"
+ " the task has already been executed "
+ "(a task can be executed only once)");

错误:(从上面的链接看起来更好)

05-30 12:59:25.955 3869-4517/com.eoinpayne.crop.cropapp E/AndroidRuntime: FATAL EXCEPTION: Thread-220
Process: com.eoinpayne.crop.cropapp, PID: 3869
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at libcore.net.UriCodec.encode(UriCodec.java:132)
at java.net.URLEncoder.encode(URLEncoder.java:57)
at com.eoinpayne.crop.cropapp.DBScraper_userVeg.run(DBScraper_userVeg.java:44)
at java.lang.Thread.run(Thread.java:818)
05-30 12:59:26.089 3869-3877/com.eoinpayne.crop.cropapp W/art: Suspending all threads took: 70.972ms
05-30 12:59:26.113 3869-3882/com.eoinpayne.crop.cropapp I/art: Background partial concurrent mark sweep GC freed 944(142KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 1612KB/2MB, paused 2.051ms total 149.697ms
05-30 12:59:26.476 3869-3909/com.eoinpayne.crop.cropapp W/EGL_emulation: eglSurfaceAttrib not implemented
05-30 12:59:26.476 3869-3909/com.eoinpayne.crop.cropapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fe768cb1f80, error=EGL_SUCCESS
05-30 12:59:26.686 3869-3909/com.eoinpayne.crop.cropapp W/EGL_emulation: eglSurfaceAttrib not implemented
05-30 12:59:26.686 3869-3909/com.eoinpayne.crop.cropapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fe768e1c2c0, error=EGL_SUCCESS
05-30 12:59:27.846 3869-3869/com.eoinpayne.crop.cropapp I/Choreographer: Skipped 34 frames! The application may be doing too much work on its main thread.
05-30 12:59:27.922 3869-3869/com.eoinpayne.crop.cropapp E/WindowManager: android.view.WindowLeaked: Activity com.eoinpayne.crop.cropapp.HomeActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{1cc88f9b V.E..... R......D 0,0-1026,422} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at com.eoinpayne.crop.cropapp.HomeActivity$HomeBackgroundTask.onPreExecute(HomeActivity.java:194)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:591)
at android.os.AsyncTask.execute(AsyncTask.java:539)
at com.eoinpayne.crop.cropapp.HomeActivity.onCreate(HomeActivity.java:82)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我的调用结构:i.stack.imgur*com/plPmA.png

我将使用我的代码的 Pastebin 编辑帖子我不能发布超过 2 个链接,因为我没有 10 个声誉..这让这变得很困难

doInBackground 不起作用的异步任务:http://pastebin.com/smtSdVmx

The code that calls it:
try {
BuildFile_userVeg buildFile = new BuildFile_userVeg(ctx);
buildFile.execute(json);
} catch (Exception e){
e.printStackTrace();
}

最佳答案

has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{1cc88f9b V.E..... R......D 0,0-1026,422} that was originally added here

当 Activity 打开 Dialog 并且 Cos 未先关闭对话框就关闭时,会发生此异常。

但是问题的真正原因就在这里

NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference

这只是意味着您正在尝试获取某个对象的长度,但该对象当前为空。我无法告诉你错误的确切原因,因为你发布的代码 fragment 不够

关于java - Android:来自可运行的异步任务 - “Activity has leaked window that was originally added here”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37526885/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com