views:

115

answers:

1

I have a Thread that downloads data from internet

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

There is an activity that needs to be updated according to downloaded data.

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 ();
   }
  }
};

Whenever I run above code I get NullPointer Exception .Please help me to update the view.

A: 

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.

bala singareddy