title: ANDROID - how to show/display JSONArray into TextView
body: <p>i try to display JSONArray from this <a href="http://www.zxccvvv.cuccfree.com/send_data.php" rel="nofollow">link</a>,,
  but when i try to running the app, that app popup an error like this
  <a href="https://postimg.org/image/g60r8gk4j/" rel="nofollow"><img src="https://s13.postimg.org/fghyw3jl3/Screenshot_2016_10_22_15_52_56_359_flix_yudi_okh.png" alt="Screenshot_2016-10-22-15-52-56-359_flix.yudi.okh.png"></a></p>
  
  <p>i try to enable javascript and search it from internet, almost all of them told me to using WebView, but i just using Textview</p>
  
  <pre><code>MainActivity.java
  </code></pre>
  
  
  
  <pre class="lang-js prettyprint-override"><code>package flix.yudi.okhttp1;
  import android.app.ProgressDialog;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.Toast;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  public class MainActivity extends AppCompatActivity {
  
      private String TAG = MainActivity.class.getSimpleName();
  
      private ProgressDialog pDialog;
      private ListView lv;
  
      // URL to get contacts JSON
      private static String url = "http://zxccvvv.cuccfree.com/send_data.php";
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; contactList;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          contactList = new ArrayList&lt;&gt;();
  
          lv = (ListView) findViewById(R.id.list);
  
          new GetContacts().execute();
      }
  
      /**
       * Async task class to get json by making HTTP call
       */
      private class GetContacts extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              // Showing progress dialog
              pDialog = new ProgressDialog(MainActivity.this);
              pDialog.setMessage("Please wait...");
              pDialog.setCancelable(false);
              pDialog.show();
  
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              HttpHandler sh = new HttpHandler();
  
              // Making a request to url and getting response
              String jsonStr = sh.makeServiceCall(url);
  
              Log.e(TAG, "Response from url: " + jsonStr);
  
              if (jsonStr != null) {
                  try {
                      JSONArray jsonObj = new JSONArray(jsonStr);
  
                      // looping through All Contacts
                      for (int i = 0; i &lt; jsonObj.length(); i++) {
                          JSONObject c = jsonObj.getJSONObject(i);
  
                          String id = c.getString("id");
                          String ask = c.getString("ask");
  
                          HashMap&lt;String, String&gt; pertanyaans = new HashMap&lt;&gt;();
  
                          pertanyaans.put("id", id);
                          pertanyaans.put("ask", ask);
  
                          contactList.add(pertanyaans);
                      }
                  } catch (final JSONException e) {
                      Log.e(TAG, "Json parsing error: " + e.getMessage());
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              Toast.makeText(getApplicationContext(),
                                      "Json parsing error: " + e.getMessage(),
                                      Toast.LENGTH_LONG)
                                      .show();
                          }
                      });
  
                  }
              } else {
                  Log.e(TAG, "Couldn't get json from server.");
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          Toast.makeText(getApplicationContext(),
                                  "Couldn't get json from server. Check LogCat for possible errors!",
                                  Toast.LENGTH_LONG)
                                  .show();
                      }
                  });
  
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
              // Dismiss the progress dialog
              if (pDialog.isShowing())
                  pDialog.dismiss();
              /**
               * Updating parsed JSON data into ListView
               * */
              ListAdapter adapter = new SimpleAdapter(
                      MainActivity.this, contactList,
                      R.layout.list_item, new String[]{"ask"}, new int[]{R.id.ask});
  
              lv.setAdapter(adapter);
          }
  
      }
  }
  </code></pre>
  
  
  
  <pre><code>HttpHandler.java
  </code></pre>
  
  
  
  <pre class="lang-js prettyprint-override"><code>package flix.yudi.okhttp1;
  
  import android.util.Log;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.ProtocolException;
  import java.net.URL;
  
  public class HttpHandler {
  
      private static final String TAG = HttpHandler.class.getSimpleName();
  
      public String makeServiceCall(String reqUrl) {
          String response = null;
          try {
              URL url = new URL(reqUrl);
              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.setConnectTimeout(7000);
              conn.setRequestMethod("GET");
              // read the response
              InputStream in = new BufferedInputStream(conn.getInputStream());
              response = convertStreamToString(in);
          } catch (MalformedURLException e) {
              Log.e(TAG, "MalformedURLException: " + e.getMessage());
              e.printStackTrace();
          } catch (ProtocolException e) {
              Log.e(TAG, "ProtocolException: " + e.getMessage());
              e.printStackTrace();
          } catch (IOException e) {
              Log.e(TAG, "IOException: " + e.getMessage());
                 e.printStackTrace();
          } catch (Exception e) {
              Log.e(TAG, "Exception: " + e.getMessage());
              e.printStackTrace();
          }
          return response;
      }
  
      private String convertStreamToString(InputStream is) {
          BufferedReader reader = new BufferedReader(new InputStreamReader(is));
          StringBuilder sb = new StringBuilder();
  
          String line;
          try {
              while ((line = reader.readLine()) != null) {
                  sb.append(line).append('\n');
              }
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              try {
                  is.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return sb.toString();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>send_data.php</p>
  </blockquote>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;?php
  include 'dbconfig.php';
  $con = new mysqli($servername, $username, $password, $dbname);
  if (mysqli_connect_errno())
    {
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
    $query = "select id,ask from pertanyaan";
  
    $result = mysqli_query($con,$query);
  
    $rows = array();
    while($r = mysqli_fetch_array($result)) {
      $rows[] =$r;
    }
  echo json_encode(array_values($rows));
  
    mysqli_close($con);
  ?&gt;
  </code></pre>
  
  <p>can someone help me how to solve the error?</p>
  
  <blockquote>
    <p>EDIT RESPONSE FROM SERVER</p>
  </blockquote>
  
  <p><a href="http://prnt.sc/cxrwgd" rel="nofollow">GET</a> <a href="http://prntscr.com/cxrwrf" rel="nofollow">POST</a></p>