title: Calling custom Dialog from AsyncTask
body: <p>I have an asynctask of which's onPostExecute i am calling a function to show a customDialog.</p>
  
  <p>This is my AsyncTask</p>
  
  <pre><code>private class DBTask extends AsyncTask&lt;Long, Boolean, Integer&gt;{ 
  ProgressDialog ServerPD = new ProgressDialog(MRRankingActivity.this); 
  
  @Override
  protected void onPreExecute() 
  {
      ServerPD = ProgressDialog.show (MRRankingActivity.this, "", "Connecting to server...", true, false);
  }//End of onPreExecute
  
  @Override
  protected Integer doInBackground(Long... params) 
  {
      int isSuccess=0;
      publishProgress(isOnline());
  
          if(isOnline())
          {
  
          getDBData();
                  if(isOK)
                      {
                      isSuccess=1;
                      }
          }   
      }
  
      return isSuccess;
  }
  
      @Override
  protected void onProgressUpdate(Boolean... isConnection) {
  // TODO Auto-generated method stub
  
  super.onProgressUpdate(isConnection);
  if(isOnline())
          {   
          ServerPD.setMessage("Retreving Data");
          }
  }
  
  @Override
  protected void onPostExecute(Integer result) {
      if (ServerPD.isShowing())
      {
          ServerPD.dismiss(); 
      }
      if(result==1)
          {
              customDialog();
          }
  
  }//End of onPostExecute
  
  }//End of DBTask
  </code></pre>
  
  <p>And this is my customDialog function</p>
  
  <pre><code>public void customDialog(){
      Dialog dialog=new Dialog(MRRankingActivity.this);
      dialog.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
      dialog.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.string.app_name );
      dialog.setContentView(R.layout.result_dialog);
      final ListView ResultView = (ListView) findViewById( R.id.ListResult );
  
      result_Adapter=new ArrayAdapter&lt;String&gt;(MRRankingActivity.this,android.R.layout.simple_list_item_1,result_Array);
  
      //Bind Array Adapter to ListView
      ResultView.setAdapter(result_Adapter);
      dialog.show();
  
  }//end of custom dialog function
  </code></pre>
  
  <p>This is my result_dialog.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  
          &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="fill_parent" 
          android:layout_width="fill_parent"
          android:orientation="vertical"&gt;
  
              &lt;ListView android:id="@+id/ListResult"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"/&gt;
  
          &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now when i run this code i am getting this error</p>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.NullPointerException
  
  at com.lalsoft.mobileranking.MRRankingActivity.customDialog(MRRankingActivity.java)
  at com.lalsoft.mobileranking.MRRankingActivity$DBTask.onPostExecute(MRRankingActivity.java)       at com.lalsoft.mobileranking.MRRankingActivity$DBTask.onPostExecute(MRRankingActivity.java)
  at android.os.AsyncTask.finish(AsyncTask.java)
  at android.os.AsyncTask.access$300(AsyncTask.java)
  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java)
  at android.os.Handler.dispatchMessage(Handler.java)
  at android.os.Looper.loop(Looper.java)
  at android.app.ActivityThread.main(ActivityThread.java)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java)
  </code></pre>
  
  <p>If i comment </p>
  
  <pre><code> //ResultView.setAdapter(result_Adapter);
  </code></pre>
  
  <p>in my customDialog function,the customDialog will show,without the Listview. This error is coming when i set the adapter to my ListView.</p>
  
  <p>How to solve this issue??What should be done?? Please help </p>