使用progressdialog的WindowLeaked异常

时间:2012-06-06 22:10:24

标签: android

尽管事实并非如此,但我试图让它变得简单。我将手机的calllog查询到数组中。然后我将这些数组放入sql表中。所以现在我在表格中有一个callog。 然后我查询最旧和最新的通话记录。这一切都发生在progressdialog中。

我的问题是这个错误:

06-06 21:24:34.954: E/AndroidRuntime(973): java.lang.NumberFormatException: Invalid long: ""
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Long.invalidLong(Long.java:125)
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Long.parseLong(Long.java:346)
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Long.parseLong(Long.java:319)
06-06 21:24:34.954: E/AndroidRuntime(973):  at com.b2creative.b2callstats.Calllogs$8.run(Calllogs.java:503)
06-06 21:24:34.954: E/AndroidRuntime(973):  at java.lang.Thread.run(Thread.java:856)
06-06 21:24:37.860: E/WindowManager(973): Activity com.b2creative.b2callstats.Calllogs has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@412e1fb0 that was originally added here
06-06 21:24:37.860: E/WindowManager(973): android.view.WindowLeaked: Activity com.b2creative.b2callstats.Calllogs has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@412e1fb0 that was originally added here
06-06 21:24:37.860: E/WindowManager(973):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
06-06 21:24:37.860: E/WindowManager(973):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
06-06 21:24:37.860: E/WindowManager(973):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)

我读到日志中的WindowLeaked异常通常发生在你开始它的活动被破坏之后你正在完成某种异步任务的时候。我还读到真正的问题应该早一点:那个无效长错误!

所以我记录了重要的部分,结果发现在进度对话框处于活动状态时没有发生任何事情。我的数组是空的,我的表也是如此。长问题是由字符串=“”引起的,因为没有数据要为字符串添加值。简而言之:

这一切都发生在我将targetSdkVersion更改为13(3.2)时。 在API级别7(2.1)中,问题没有发生。

在这里您可以看到有问题的部分:

pd = ProgressDialog.show(Calllogs.this, "Please wait..", "Loading data. This may take a few seconds based on the number of calls.", false, true);

Thread thread = new Thread(new Runnable() {  
    public void run() {
        //query calllog into arrays, populating table, getting date of the last and first added record, but nothing seems to be happening

        //here comes the error:
        String dA = "";
        HotOrNot infod = new HotOrNot(Calllogs.this);
        infod.open();
        Cursor cursorA = infod.getAllTitles_DateLimit1("DESC");
        if (cursorA.moveToFirst()){
            do{
                dA = cursorA.getString(5);
            }while (cursorA.moveToNext());
        }

        Log.i("dA", dA + ""); //null
        d1 = dA;
        infod.close();
        cal1.setTimeInMillis(Long.parseLong(dA));  //this is the first error. it looks like the table is empty.

        handler.sendEmptyMessage(0);

        lv1.post(new Runnable() {
            public void run() {
                lv1.setAdapter(adapter);
            }
        }); 
    }
});

thread.start();

我添加了

@Override
protected void onStop(){
    super.onStop();
    if (pd != null){
    }
    pd.dismiss();
    pd = null;
}

我还将此代码添加到onDestroy和onPause方法中,但是徒劳无功。

所以基本上对我来说这意味着logcat指向的变量没有值(至少不是可以转换为Long类型的值),因为活动因某事而结束,并且因为漏洞窗口错误而发生活动已完成,但进度对话框已打开。或者活动结束,因为变量值不正确,但progressdialog仍然打开,为什么?魔鬼的圈子,任何想法?

1 个答案:

答案 0 :(得分:0)

猜猜:你没有启动填充你的适配器的Runnable接口,所以也许这是因为一切都是空的?