title: Thread and handler not work in android
body: <p>I use loading before load completed listview</p>
  
  <p>This code worked  : </p>
  
  <pre><code>@Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  final ListView listContent = (ListView) findViewById(R.id.listContent);
          adapter = new AdapterNote(G.tasks);
          listContent.setAdapter(adapter);
          Commands.readData();
          adapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>But after changing to the below code , application crashed and force closed :</p>
  
  <pre><code>@Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  startDialog();
  }
  
  ProgressDialog pd;
  
  
      private void startDialog() {
  
          pd = ProgressDialog.show(NoteActivity.this, "title", "loading");
  
          new Thread(new Runnable() {
  
              @Override
              public void run() {
                  final ListView listContent = (ListView) findViewById(R.id.listContent);
          adapter = new AdapterNote(G.tasks);
          listContent.setAdapter(adapter);
          Commands.readData();
          adapter.notifyDataSetChanged();
  
                  handler.sendEmptyMessage(0);
              }
          }).start();
      }
  
      Handler handler = new Handler() {
  
                          @Override
                          public void handleMessage(Message msg) {
                              pd.dismiss();
                          }
                      };
  </code></pre>
  
  <p>In log cat these errors occurred :</p>
  
  <pre><code>03-08 00:27:09.734: E/AndroidRuntime(334): FATAL EXCEPTION: main
  03-08 00:27:09.734: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NoteProject.download.app/com.NoteProject.download.app.NoteNoteProjectActivity}: java.lang.NullPointerException
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.os.Handler.dispatchMessage(Handler.java:99)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.os.Looper.loop(Looper.java:123)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at java.lang.reflect.Method.invokeNative(Native Method)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at java.lang.reflect.Method.invoke(Method.java:521)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at dalvik.system.NativeStart.main(Native Method)
  03-08 00:27:09.734: E/AndroidRuntime(334): Caused by: java.lang.NullPointerException
  03-08 00:27:09.734: E/AndroidRuntime(334):  at com.NoteProject.download.app.NoteNoteProjectActivity$2.onScroll(NoteNoteProjectActivity.java:79)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:675)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.widget.AbsListView.setOnScrollListener(AbsListView.java:664)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at com.NoteProject.download.app.NoteNoteProjectActivity.onCreate(NoteNoteProjectActivity.java:69)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-08 00:27:09.734: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  03-08 00:27:09.734: E/AndroidRuntime(334):  ... 11 more
  </code></pre>
  
  <p>How to fix it ?</p>
  
  <p>In <code>commands.readdata()</code> , return listview from web</p>
  
  <p>Thx</p>