Threading while parsing
<p>Let me first clarify my question.</p>

<p>I am doing this,parsing datas (Using DOM) and bind it on my listview. Everything works fine until I found out that it is taking to long to respond. To accomplish that, I come up with an idea that I should put it inside a Thread. So Ive added a class that extends thread.</p>

<p>My code on parsing</p>

<pre><code>  public  void SetFriendString()
{
    XMLParser parser2 = new XMLParser(); 
    parser2.getXmlFromUrl(URL_HERE); 

      //HTTP POST
      String url_Getmembermob= URL_FBFRIEND ;
      //String xml_getMembermob=null;
      try {
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(url_Getmembermob);

      List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(4); 
      nameValuePairs.add(new BasicNameValuePair("oAuth", "Test123"));
      nameValuePairs.add(new BasicNameValuePair("""", modGen...));
      nameValuePairs.add(new BasicNameValuePair("", modGen....));
      nameValuePairs.add(new BasicNameValuePair("", "here"));

      //Log.i("nameValuePairs", "nameValuePairs=" + nameValuePairs);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = httpclient.execute(httppost);

        HttpEntity httpEntity = httpResponse.getEntity();

        FBFRIENDS = EntityUtils.toString(httpEntity);    

        Button GetFriends =(Button) findViewById(R.id.btnAllFriends);
        GetFriends.setBackgroundDrawable(getResources().getDrawable(R.drawable.leftcornerclicked));
        KEY_FRIENDSDATA = FBFRIENDS;

        Log.i("xml-return",""+ FBFRIENDS);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace(); 
    }catch (ClientProtocolException e) { 
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
</code></pre>

<p>And added this class</p>

<pre><code>        public class thread extends Thread {
        public void run() {
            SetFriendString();
            //SetMyRequestString();
            //SetMyFriendRequestString();
            pDialog.dismiss();
            }
        }
</code></pre>

<p>Now I am calling this class on my OnCreate</p>

<pre><code>    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_friends);
    mContext = this;
    pDialog = new ProgressDialog(this);
    pDialog.setMessage("Loading All Merchants...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pDialog.show();
    //Set All Required data
    thread t = new thread();
    t.start();
</code></pre>

<p>Now my app forces to close. Using debugger I found out that the thread skips my methods. Why is that?</p>

<pre><code>10-29 11:13:29.411: E/AndroidRuntime(2463): FATAL EXCEPTION: main
10-29 11:13:29.411: E/AndroidRuntime(2463): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fb.connect/com.fb.connect.MyFriendsAdd}: java.lang.NullPointerException
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.os.Looper.loop(Looper.java:130)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at java.lang.reflect.Method.invoke(Method.java:507)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at dalvik.system.NativeStart.main(Native Method)
10-29 11:13:29.411: E/AndroidRuntime(2463): Caused by: java.lang.NullPointerException
10-29 11:13:29.411: E/AndroidRuntime(2463):     at com.fb.connect.MyFriendsAdd.SetAllFacebookFriends(MyFriendsAdd.java:193)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at com.fb.connect.MyFriendsAdd.onCreate(MyFriendsAdd.java:145)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-29 11:13:29.411: E/AndroidRuntime(2463):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-29 11:13:29.411: E/AndroidRuntime(2463):     ... 11 more
</code></pre>
