title: How to set List Adapter in onPostExecute Asynctask?
body: <p>Good Day everyone,</p>
  
  <p>I have some problem here. I make a web service call in AsyncTask DoInBackground.</p>
  
  <p>And I wanted to set list adapter, but I got error</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
  </code></pre>
  
  <p>Now how to set list adapter in post execute or something?</p>
  
  <p>My code </p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_profile);
      progressBar = (ProgressBar)findViewById(R.id.prgLoading);
  
  
       //Initialize the ListView
      final ListView lvProf = (ListView)findViewById(R.id.lvProfile);
  
      //call the asynctask cals and add item to the list.
      new LoadDataForActivity().execute();
  
     //Set adapter , but i got error here
      lvProf.setAdapter(new ListProfileAdapter(this,mItems));
  
  
  
  }
  
  private class LoadDataForActivity extends AsyncTask&lt;Void, Void, Void&gt; {
      @Override
      protected void onPreExecute() {
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                  WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
          progressBar.setVisibility(View.VISIBLE);
          progressBar.setIndeterminate(false);
          progressBar.setClickable(false);
      }
      @Override
      protected Void doInBackground(Void... params) {
  
          getAll();
          getTotalLeaveBalance();
          getMedicalBalance();
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
      //here is I add the item to my list (mitems)
          try{
              ResponseServiceMedicalBalance = ResponseServiceMedicalBalance.replace("\\\"", "\"");
              ResponseServiceMedicalBalance = ResponseServiceMedicalBalance.substring(1, ResponseServiceMedicalBalance.length() - 1);
  
              JSONParser jsonParser = new JSONParser();
              JSONObject jsonObject = (JSONObject) jsonParser.parse(ResponseServiceMedicalBalance);
              String Status = jsonObject.get("Status").toString();
  
              if (Status == "true") {
                  // JSONArray structure = (JSONArray) jsonObject.get("DataList");
                  String dataku = jsonObject.get("DataList").toString();
                  mItems = new ArrayList&lt;ListProfileItem&gt;();
                  try {
                      dataku = ANGGACRYYPT.decrypt(Enc_Pass, dataku);
                  }catch (GeneralSecurityException e){
                      //handle error - could be due to incorrect password or tampered encryptedMsg
                  }
  
                  JSONParser parser = new JSONParser();
                  JSONArray structure = (JSONArray) parser.parse(dataku);
                  for (int i = 0; i &lt; structure.size(); i++) {
                      JSONObject data = (JSONObject) structure.get(i);
                      item = new ListProfileItem();
                      item.claimpostname = data.get("claim_post_name").toString();
                      String claimamount = data.get("max_limit_per_year").toString();
                      if (claimamount!=("0.0"))
                      {
                          Double amount = Double.parseDouble(claimamount);
                          DecimalFormat formatter = new DecimalFormat("#,###.00");
                          String AmountFormatted = formatter.format(amount);
                          item.claimpostamount = AmountFormatted;
                      }
                      else
                      {
                          item.claimpostamount = data.get("max_limit_per_year").toString();
                      }
                      mItems.add(item);
                  }
                  // initialize and set the list adapter
  
              }
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>