Android thread handler NullPointerException

Posted by Realn0whereman on Stack Overflow See other posts from Stack Overflow or by Realn0whereman
Published on 2010-12-19T15:53:58Z Indexed on 2010/12/24 6:54 UTC
Read the original article Hit count: 143

Filed under:
|

So this null pointer is confusing me. I believe it is a scope issue.

My main activity looks like this:

public class App extends Activity {  
  ProgressDialog progressDialog;  
  ProgressThread progressThread;

Then inside of the oncreate I do this:

  ProgressDialog progressDialog = new ProgressDialog(this);  
  progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);  
  progressDialog.setMessage("Fetching Images...");  
  ProgressThread progressThread = new ProgressThread(handler,mImageIds,mImages);  
  progressThread.start();    
  progressDialog.show();

THEN inside progressThread which is a separate class I do

mHandler.sendMessage(mHandler.obtainMessage());

Now up until this point i believe it behaves as it should. I have my handler hanging out in class scope right underneath my oncreate

final Handler handler = new Handler() {  
  public void handleMessage(Message msg){  
    progressDialog.hide();  
    progressThread.interrupt();  
  }  
 };

The program thinks that progressDialog and progressThread are declared, but are null. Why would they be null if I instantiate in my oncreate.

© Stack Overflow or respective owner

Related posts about android

Related posts about multithreading