关于notifyDataSetChanged()的WinDeath

时间:2013-12-19 13:39:50

标签: android android-listview android-sqlite

您好我有以下问题:

data.clear();
data.addAll(datasource.getFilesInFolder());  //gets the data from Sqlite database
adapter.notifyDataSetChanged();

生成此logCat输出:

 12-19 14:34:30.864: W/Binder(986): Caught a RuntimeException from the binder stub implementation.
 12-19 14:34:30.864: W/Binder(986): java.lang.NullPointerException
 12-19 14:34:30.864: W/Binder(986):     at        android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
 12-19 14:34:30.864: W/Binder(986):     at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
 12-19 14:34:30.864: W/Binder(986):     at android.os.Binder.execTransact(Binder.java:404)
 12-19 14:34:30.864: W/Binder(986):     at dalvik.system.NativeStart.run(Native Method)
 12-19 14:34:30.864: W/InputMethodManagerService(757): Got RemoteException sending setActive(false) notification to pid 30040 uid 10174

此异常导致WIN DEATH ...

好吧,我意识到也许是反过来,WIN DEATH导致这个日志输出,因为在日志WINDEATH之前来了,那么我不知道为什么会出现windeath。

我的适配器是扩展的BaseAdapter,没有什么特别之处。以下是非常奇怪的:

上面提到的一段代码位于自定义侦听器中,该侦听器是从另一个类触发的。当我将有问题的部分放在听众之外时,它运作良好。

我的意思是Caught a RuntimeException from the binder stub implementation吗?这可能是数据库的问题吗?或者也许是我的自定义听众? 任何人都知道什么是错的?

2 个答案:

答案 0 :(得分:2)

我在执行并发操作时遇到过这个问题。例如,参见this thread(fling + service)和this one(在2个主题的画布上绘图)。

你在谈论一个不同类的自定义监听器,你是否也可以同时做几件事?

答案 1 :(得分:1)

您应该直接将数据添加到适配器中。

而不是做

data.clear();
data.addAll(datasource.getFilesInFolder());  //gets the data from Sqlite database
adapter.notifyDataSetChanged();

你应该做

if(adapter!=null)
{
    adapter.clear();
    adapter.addAll(datasource.getFilesInFolder());  //gets the data from Sqlite database
    adapter.notifyDataSetChanged();
}

我认为适配器为null,导致您的情况出现问题

相关问题