Android:来自Runnable的异步任务 - “活动已泄露最初添加的窗口”

时间:2016-05-30 13:26:26

标签: java android android-asynctask runnable

我的" doInBackground"从一个可运行的人那里打来电话似乎无法解雇。任何人都可以帮我解决我的代码吗?

此链接显示调用后台/可运行任务的一般流程。 (也有我的错误+笔记。我也会屏幕截图并在下面张贴所有内容) lucidchart * COM /邀请/接受/ 1edf5782-b8d5-4ee6-bc37-4eb3bbfe56a9

似乎错误正在发生,因为它正在尝试处理空文件,似乎正在执行preexecute,文件被删除,但doInBacground不是,文件重建的地方。

似乎问题已经被对话。显示/解雇,这必须是因为" doInBackground"没有跑。

调试时我在异步类中遇到此异常: 调试时出现此错误

@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

我将使用代码的粘贴代码编辑帖子 我不能发布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();
        }

1 个答案:

答案 0 :(得分:0)

  

泄漏了最初添加的窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {1cc88f9b VE .... R ...... D 0,0-1026,422}

当“活动”打开“对话框”并且“Cos”关闭而未先关闭对话框时,会发生此异常。

但问题的真正原因在于

  

NullPointerException:尝试调用虚方法&#39; int java.lang.String.length()&#39;在空对象引用上

它只是意味着您正在尝试获取某个对象的长度,但该对象当前为null。我无法确定您错误的原因,因为您发布的代码段不够