How to Display Data from MySQL Database to Android by inserting it into Table?
<p>I'm Creating an Android App that shows tables which the data's came from MySQL Database. I have my Codes Running without Errors.. BUT the data from DB is not displaying on the Table. By the way i'm using Eclipse as my compiler.</p>

<p>This is my Database :</p>

<p><a href="https://i.stack.imgur.com/y7bBv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y7bBv.jpg" alt="enter image description here"></a></p>

<p>This is My PHP codes with Json :</p>

<pre><code>&lt;?php 

$con=mysqli_connect("localhost","root","");
mysqli_select_db($con,"qstatslite")or die("error");


$q = mysqli_query($con,"SELECT * FROM queue_stats ORDER BY queue_stats_id DESC LIMIT 20");
while($row=mysqli_fetch_assoc($q))
$json_output[]=$row;

print(json_encode($json_output));



?&gt;
</code></pre>

<p>And This is My Java Codes for DB :</p>

<pre><code>import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class GetDataFromDB {

    public String getDataFromDB() {
        try {

            HttpPost httppost;
            HttpClient httpclient;
            httpclient = new DefaultHttpClient();
            httppost = new HttpPost(
                    "http:///192.168.1.87/Projects/Callchart/selectall.php"); 
            ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
            final String response = httpclient.execute(httppost,
                    responseHandler);

            return response.trim();

        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            return "error";
        }
    }
}
</code></pre>

<p>And This is my MainActivity :</p>

<pre><code>import java.util.ArrayList;
import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;

public class MainActivity extends Activity {

    String data = "";
    TableLayout tl;
    TableRow tr;
    TextView label;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tl = (TableLayout) findViewById(R.id.maintable);

        final GetDataFromDB getdb = new GetDataFromDB();
        new Thread(new Runnable() {
            public void run() {
                data = getdb.getDataFromDB();
                System.out.println(data);

                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        ArrayList&lt;Users&gt; queue_stats = parseJSON(data);
                        addData(queue_stats);                       
                    }
                });

            }
        }).start();
    }

    public ArrayList&lt;Users&gt; parseJSON(String result) {
        ArrayList&lt;Users&gt; users = new ArrayList&lt;Users&gt;();
        try {
            JSONArray jArray = new JSONArray(result);
            for (int i = 0; i &lt; jArray.length(); i++) {
                JSONObject json_data = jArray.getJSONObject(i);
                Users user = new Users();
                user.setqueue_stats_id(json_data.getInt("queue_stats_id"));
                user.setdatetime(json_data.getInt("datetime"));
                user.setqname(json_data.getInt("qname"));
                user.setqagent(json_data.getInt("qagent"));
                user.setqevent(json_data.getInt("qevent"));
                user.setinfo1(json_data.getString("info1"));
                user.setinfo2(json_data.getString("info2"));
                user.setinfo3(json_data.getString("info3"));
                users.add(user);
            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());  
        }
        return users;
    }


    void addHeader(){
        /** Create a TableRow dynamically **/
        tr = new TableRow(this);

        /** Creating a TextView to add to the row **/
        label = new TextView(this);
        label.setText("DateTime");
        label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        label.setPadding(5, 5, 5, 5);
        label.setBackgroundColor(Color.GRAY);
        LinearLayout Ll = new LinearLayout(this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(5, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(label,params);
        tr.addView((View)Ll); // Adding textView to tablerow.

        /** Creating Qty Button **/
        TextView queue= new TextView(this);
        queue.setText("Queue");
        queue.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        queue.setPadding(5, 5, 5, 5);
        queue.setBackgroundColor(Color.GRAY);
        Ll = new LinearLayout(this);
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(queue,params);
        tr.addView((View)Ll); // Adding textview to tablerow.

        /** Creating Qty Button **/
        TextView agent = new TextView(this);
        agent.setText("Agent");
        agent.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        agent.setPadding(5, 5, 5, 5);
        agent.setBackgroundColor(Color.GRAY);
        Ll = new LinearLayout(this);
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(agent,params);
        tr.addView((View)Ll);

        TextView event = new TextView(this);
        event.setText("Event");
        event.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        event.setPadding(5, 5, 5, 5);
        event.setBackgroundColor(Color.GRAY);
        Ll = new LinearLayout(this);
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(event,params);
        tr.addView((View)Ll);

        TextView info1 = new TextView(this);
        info1.setText("Info1");
        info1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        info1.setPadding(5, 5, 5, 5);
        info1.setBackgroundColor(Color.GRAY);
        Ll = new LinearLayout(this);
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(info1,params);
        tr.addView((View)Ll);

        TextView info2 = new TextView(this);
        info2.setText("Info1");
        info2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        info2.setPadding(5, 5, 5, 5);
        info2.setBackgroundColor(Color.GRAY);
        Ll = new LinearLayout(this);
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(info2,params);
        tr.addView((View)Ll);

        TextView info3 = new TextView(this);
        info3.setText("Info1");
        info3.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        info3.setPadding(5, 5, 5, 5);
        info3.setBackgroundColor(Color.GRAY);
        Ll = new LinearLayout(this);
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 5, 5, 5);
        //Ll.setPadding(10, 5, 5, 5);
        Ll.addView(info3,params);
        tr.addView((View)Ll);

         // Add the TableRow to the TableLayout
        tl.addView(tr, new TableLayout.LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT));
    }

    @SuppressWarnings({ "rawtypes" })
    public void addData(ArrayList&lt;Users&gt; users) {

        addHeader();

        for (Iterator i = users.iterator(); i.hasNext();) {

            Users p = (Users) i.next();

            /** Create a TableRow dynamically **/
            tr = new TableRow(this);

            /** Creating a TextView to add to the row **/
            label = new TextView(this);
            label.setText(p.getdatetime());
            label.setId(p.getqueue_stats_id());
            label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
            label.setPadding(5, 5, 5, 5);
            label.setBackgroundColor(Color.GRAY);
            LinearLayout Ll = new LinearLayout(this);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            params.setMargins(5, 2, 2, 2);
            //Ll.setPadding(10, 5, 5, 5);
            Ll.addView(label,params);
            tr.addView((View)Ll); // Adding textView to tablerow.

            /** Creating Qty Button **/
            TextView place = new TextView(this);
            place.setText(p.getqname());
            place.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
            place.setPadding(5, 5, 5, 5);
            place.setBackgroundColor(Color.GRAY);
            Ll = new LinearLayout(this);
            params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            params.setMargins(0, 2, 2, 2);
            //Ll.setPadding(10, 5, 5, 5);
            Ll.addView(place,params);
            tr.addView((View)Ll); // Adding textview to tablerow.

             // Add the TableRow to the TableLayout
            tl.addView(tr, new TableLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT));
        }
    }
}
</code></pre>

<p>Can someone help me solve this one?</p>

<p>This is the output so far.. No data display: </p>

<p><a href="https://i.stack.imgur.com/9rki8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9rki8.png" alt="enter image description here"></a></p>