Displaying data from MySQL into TextView in Android Studio
<p>I want to display data from MySQL into Android using TextView,, but when I'm running the app, its goes force stop itself.</p>

<p>Can someone help me how to fix it? any idea would be nice.</p>

<p><strong><code>dbconfig.php</code></strong>:</p>



<pre class="lang-html prettyprint-override"><code>&lt;?php

//This script is designed by Android-Examples.com
//Define your host here.
$servername = "localhost";
//Define your database username here.
$username = "root";
//Define your database password here.
$password = "";
//Define your database name here.
$dbname = "u727224026_demo";

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

<p><strong><code>send_data.php</code></strong></p>



<pre class="lang-html prettyprint-override"><code>&lt;?php
include 'dbconfig.php';


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn-&gt;connect_error) {
    die("Connection failed: " . $conn-&gt;connect_error);
} 

$sql = "SELECT * FROM TextViewTable";
$result = $conn-&gt;query($sql);

if ($result-&gt;num_rows &gt; 0) {

    // output data of each row
    while($row[] = $result-&gt;fetch_assoc()) {

       $json = json_encode($row);


    }
} else {
    echo "0 results";
}
echo $json;
$conn-&gt;close();
?&gt;
</code></pre>

<p><strong><code>MainActivity.java</code></strong></p>



<pre class="lang-js prettyprint-override"><code>package flix.yudi.kuesioner2;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends Activity {

    TextView textview;
    JSONObject json = null;
    String str = "";
    HttpResponse response;
    Context context;
    ProgressBar progressbar;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressbar = (ProgressBar)findViewById(R.id.progressBar1);
        textview = (TextView)findViewById(R.id.textView1);
        button = (Button)findViewById(R.id.button1);

        progressbar.setVisibility(View.GONE);

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                progressbar.setVisibility(View.VISIBLE);

                new GetTextViewData(context).execute();

            }
        });
    }


    private class GetTextViewData extends AsyncTask&lt;Void, Void, Void&gt;
    {
        public Context context;


        public GetTextViewData(Context context)
        {
            this.context = context;
        }

        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... arg0)
        {

            HttpClient myClient = new DefaultHttpClient();
            HttpPost myConnection = new HttpPost("http://192.168.100.6/a_test/send-data.php");

            try {
                response = myClient.execute(myConnection);
                str = EntityUtils.toString(response.getEntity(), "UTF-8");

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }


            try{
                JSONArray jArray = new JSONArray(str);
                json = jArray.getJSONObject(0);



            } catch ( JSONException e) {
                e.printStackTrace();
            }

            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
        protected void onPostExecute(Void result)
        {
            try {
                textview.setText(json.getString("ServerData"));

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            //Hiding progress bar after done loading TextView.
            progressbar.setVisibility(View.GONE);

        }
    }


}
</code></pre>

<p><strong><code>activity_main.xml</code></strong></p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jsonparsingfromurltextview_android_examples.com.MainActivity" &gt;

&lt;TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="TextView Static Text Before Load"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center"/&gt;

&lt;ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="17dp" /&gt;

&lt;Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="150dp"
    android:text="Click Here to Load TextView data dynamically from MySQL Database Online Using JSON Parsing" /&gt;
</code></pre>

<p></p>

<p>logcat error notif</p>

<blockquote>
  <p>10-04 15:41:44.516 22210-22210/flix.yudi.kuesioner2 E/AndroidRuntime: FATAL EXCEPTION: main
  Process: flix.yudi.kuesioner2, PID: 22210
  java.lang.NullPointerException
  at flix.yudi.kuesioner2.MainActivity$GetTextViewData.onPostExecute(MainActivity.java:114)
                                                                            at flix.yudi.kuesioner2.MainActivity$GetTextViewData.onPostExecute(MainActivity.java:60)
                                                                            at android.os.AsyncTask.finish(AsyncTask.java:632)
                                                                            at android.os.AsyncTask.access$600(AsyncTask.java:177)
                                                                            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:146)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5593)
                                                                            at java.lang.reflect.Method.invokeNative(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:515)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                                                                            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
                                                                            at dalvik.system.NativeStart.main(Native Method) </p>
</blockquote>

<p>I tried to find how to fix it, but still nothing,
please help me.</p>

<p>ADDITIONAL INFO RESPONSE FROM HTTP_REQUESTER:</p>

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