title: Android JSON parsing - Read data from a MySQL db , parsing & display result in a ListView
body: <p>I'm following a tutorial about <code>Android JSON parsing</code> on youtube. I want to read data from <code>MySQL db</code> parse into <code>JSON format</code> and display them in a list view in my Android app.</p>
  
  <p>I have a created a <code>PHP</code> to <code>decode JSON data</code> and it shows in my Android app. But when I try to display them in a List View app shows a <code>blank screen</code>.</p>
  
  <p>This is my Main Activiy class.</p>
  
  <pre><code>public class MainActivity extends Activity {
  String json_string;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  public void getJSON(View view){
      new AsyncTaskRunner().execute();
  }
  
  class AsyncTaskRunner extends AsyncTask&lt;Void, Void, String&gt; {
  
      String JSON_STRING;
      String json_url;
      TextView textView;
  
  
      @Override
      protected void onPostExecute(String result) {
          TextView textView= (TextView)findViewById(R.id.textView);
          textView.setText(result);
          json_string=result;
  
      }
  
      @Override
      protected String doInBackground(Void... voids) {
          try {
              URL url = new URL(json_url);
              HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
  
              InputStream inputStream=httpURLConnection.getInputStream();
              BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(inputStream));
  
              StringBuilder stringBuilder =new StringBuilder();
  
              while((JSON_STRING=bufferedReader.readLine())!=null){
                  stringBuilder.append(JSON_STRING+"\n");
              }
  
              bufferedReader.close();
              inputStream.close();
              httpURLConnection.disconnect();
  
              return stringBuilder.toString().trim();
  
          }catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return null;
  
      }
  
      @Override
      protected void onPreExecute() {
  
          json_url="http://10.0.2.2/ahala_new/json_get_data.php";
      }
  
  
      @Override
      protected void onProgressUpdate(Void... values) {
  
          super.onProgressUpdate(values);
      }
  }
  
  public void parseJSON(View view)
  {
      if(json_string==null){
          Toast.makeText(getApplicationContext(),"First get JSON Data",Toast.LENGTH_LONG).show();
      }
      else{
          Intent intent=new Intent(this,ListView_Display.class);
          intent.putExtra("json_data",json_string);
          startActivity(intent);
      }
  }}
  </code></pre>
  
  <p>Display List View class</p>
  
  <pre><code>public class ListView_Display extends Activity {
  String json_string;
  JSONObject jsonObject;
  JSONArray jsonArray;
  PromoAdapter promoAdapter;
  ListView listView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.display_listview_layout);
  
      listView= (ListView) findViewById(R.id.listView);
      listView.setAdapter(promoAdapter);
  
      promoAdapter =new PromoAdapter(this,R.layout.row_layout);
      json_string =getIntent().getExtras().getString("json_data");
  
      try {
          jsonObject = new JSONObject(json_string);
          jsonArray=jsonObject.getJSONArray("server_response");
          int count=0;
          String name,description,price;
          while (count&lt;jsonObject.length()){
  
              JSONObject SA=jsonArray.getJSONObject(count);
              name=SA.getString("name");
              description=SA.getString("description");
              price=SA.getString("price");
  
              Promotions promotions=new Promotions(name,description,price);
              promoAdapter.add(promotions);
              count++;
  
          }
  
      } catch (JSONException e) {
          e.printStackTrace();
      }
  
  }}
  </code></pre>
  
  <p>Custom List View Adapter class</p>
  
  <pre><code>public class PromoAdapter extends ArrayAdapter{
  List list=new ArrayList();
  public PromoAdapter(Context context, int resource) {
      super(context, resource);
  }
  
  
  public void add(Promotions object){
      super.add(object);
      list.add(object);
  }
  
  @Override
  public int getCount(){
      return list.size();
  }
  
  @Override
  public Object getItem(int position){
      return list.get(position);
  }
  
  @Override
  public View getView(int position,View convertView,ViewGroup parent){
      View row;
      row=convertView;
      PromotionHolder promotionHolder;
      if(row==null){
          LayoutInflater layoutInflater= (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          row=layoutInflater.inflate(R.layout.row_layout,parent,false);
  
          promotionHolder = new PromotionHolder();
          promotionHolder.txName=(TextView)row.findViewById(R.id.txName);
          promotionHolder.txDesc=(TextView)row.findViewById(R.id.txDesc);
          promotionHolder.txPrice=(TextView)row.findViewById(R.id.txPrice);
  
          row.setTag(promotionHolder);
  
      }
  
      else{
          promotionHolder= (PromotionHolder) row.getTag();
      }
      Promotions promotions=(Promotions)this.getItem(position);
      promotionHolder.txName.setText(promotions.getName());
      promotionHolder.txDesc.setText(promotions.getDescription());
      promotionHolder.txPrice.setText(promotions.getPrice());
  
      return row;
  }
  
  static class PromotionHolder{
      TextView txName,txDesc,txPrice;
  
  }
  
  }
  </code></pre>
  
  <p>Please help me to fix this issue.</p>