Take the 2-minute tour ×

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.

share|improve this question
Can we have a stack trace? P.S. naming class variables and temporary variables the same leads to confusion! –  Tom Medley Sep 20 '10 at 10:43
fredley I am trying to use "myHandler" of Bp thread to sendMessage to Activity Hp to update UI . myHandler is just declared in Bp It is handled in Activity Hp. I hope I am in correct direction. –  100rabh Sep 20 '10 at 14:31
SOLVED:Just wrote the code neatly & it worked –  100rabh Dec 1 '10 at 7:01
add comment

2 Answers

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.

share|improve this answer
add comment
up vote 0 down vote accepted

Solved the issue by rewriting the code neatly & it worked well.Seems earlier there were problems setting Handler.

share|improve this answer
add comment

Your Answer


