0

我有一个从互联网下载数据的线程

public class Bp implements Runnable
{
Handler myHandler;
public void setHandler(Handler myHandler)
{ this.myHandler=myHandler; }
....
myHandler.sendEmptyMessage (0);
}

有一个活动需要根据下载的数据进行更新。

public class Hp extends Activity implements Runnable
{
....
public Handler myHandler = new Handler() {
  public void  handleMessage(Message msg) {
 //TODO handle myHandler from "Bp" Thread     
 //TODO remove Queue's View 
   if(m_adapter2.getCount ()==6)
   {
    m_adapter2.remove (queue);         //removing view named queue from adapter
    m_adapter2.notifyDataSetChanged ();
   }
  }
};

每当我运行上面的代码时,我都会得到 NullPointer Exception 。请帮我更新视图。

4

2 回答 2

0

yes that's correct. You are creating the handler in the BP thread.. but what you need is to create it in the context of the main or GUI thread running in the HP activity because the MessageQueue of the main/GUI thread is in question here as you're updating it with data received from the other thread.

于 2010-10-20T22:50:16.733 回答
-3

通过巧妙地重写代码解决了这个问题,它运行良好。似乎早些时候设置处理程序有问题。

于 2010-12-01T07:03:44.713 回答