title: Comments not showing in ListView inside Asynctask - android
body: <p>I have an <code>AsyncTask</code> that uses a JSON function to get comments in the <code>doInBackground</code> method. It then sends the array of comments to <code>onPostExecute</code> where it places the <code>JSONArray</code> into a <code>String[]</code> then is places the string into <code>setListAdapter</code>. The code doesn't crash and everything seems to work right but the comments are not being shown inside the <code>Activity</code>.</p>
  
  <pre><code>class loadComments extends AsyncTask&lt;JSONObject, String, JSONObject&gt; {
  
      @Override
      protected JSONObject doInBackground(JSONObject... params) {
          final JSONObject json2 = CollectComments.collectComments(usernameforcomments,
                  offsetNumber);
          return json2;
      }
  
      @Override
      protected void onPostExecute(JSONObject json2) {
          try {
              if (json2.getString(KEY_SUCCESS) != null) {
                  registerErrorMsg.setText("");
                  final String res2 = json2.getString(KEY_SUCCESS);
                  if (Integer.parseInt(res2) == 1) {
  
                      final JSONArray array = json2.getJSONArray(KEY_COMMENT);
                      final String comments[] = new String[array.length()];
                      for (int i = 1; i &lt;= array.length(); i++) {
                          comments[i] = array.getString(i);
                      }
                      setListAdapter(new ArrayAdapter&lt;String&gt;(DashboardActivity.this,
                              R.layout.list_item, R.id.label, comments));
  
                  }// end if key is == 1
                  else {
                      // Error in registration
                      registerErrorMsg.setText(json2.getString(KEY_ERROR_MSG));
                  }// end else
              }// end if
          } // end try
          catch (final JSONException e) {
              e.printStackTrace();
          }// end catch
      }
  }
  
  
  new loadComments().execute();
  </code></pre>
  
  <p>My xml for the activity is this </p>
  
  <p></p>
  
  <pre><code>&lt;RelativeLayout
      android:id="@+id/dashboardRelative"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#CCCCCC"
      android:orientation="vertical" &gt;
  
      &lt;Button
          android:id="@+id/btnPost"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/dashboard_post"
          android:paddingBottom="10dip"
          android:paddingTop="10dip"
          android:text="@string/post"
          android:textColor="#FFFFFF"
          android:textSize="20sp"
          android:textStyle="bold" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/commentSection"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/btnPost"
          android:layout_margin="20dip"
          android:orientation="vertical" &gt;
  
          &lt;ListView
              android:id="@android:id/list"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;!-- Error message --&gt;
  
      &lt;TextView
          android:id="@+id/collectComment_error"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/commentSection"
          android:layout_gravity="center"
          android:gravity="center"
          android:padding="10dip"
          android:textColor="#e30000"
          android:textStyle="bold" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>