0

我试着让它简单,即使它不是。我将手机的通话记录查询到数组中。然后我将这些数组放入一个 sql 表中。所以现在我在表格中有一个 calllog。然后我查询最旧和最新的通话记录。这一切都发生在进度对话框中。

我的问题是这个错误:

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 类型的值),因为活动由于某些原因而结束,并且由于活动完成而发生泄漏窗口错误但是进度对话框打开。或者活动结束是因为变量的值不正确,但是进度对话框仍然打开,为什么?恶魔圈,有什么想法吗?

4

1 回答 1

0

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

于 2012-06-07T13:49:41.437 回答