title: Android - mysql php
body: <p><strong>this program is to get a name from online mysql database by entering an id and sending request to php online file and the response is the name
  what is wrong with the code ? I get no name</strong></p>
  
  <p><strong>xml</strong></p>
  
  <pre><code>//activity_main.xml
  
      &lt;LinearLayout
          android:orientation="vertical"
          android:layout_height="495dp"
          android:layout_width="368dp"
          tools:layout_editor_absoluteY="8dp"
          tools:layout_editor_absoluteX="8dp"
          tools:ignore="MissingConstraints"&gt;
  
          &lt;LinearLayout
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;
  
              &lt;EditText
                  android:id="@+id/editTextId"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"/&gt;
              &lt;Button
                  android:id="@+id/buttonGet"
                  android:text="Get"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" /&gt;
  
          &lt;/LinearLayout&gt;
          &lt;TextView
              android:id="@+id/textViewResult"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Main class</strong></p>
  
  <pre><code>//MainActivity.class
  
  public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
      private EditText editTextId;
      private Button buttonGet;
      private TextView textViewResult;
  
      private ProgressDialog loading;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          editTextId = (EditText) findViewById(R.id.editTextId);
          buttonGet = (Button) findViewById(R.id.buttonGet);
          textViewResult = (TextView) findViewById(R.id.textViewResult);
  
          buttonGet.setOnClickListener(this);
      }
  
      private void getData() {
          String id = editTextId.getText().toString().trim();
          if (id.equals("")) {
              Toast.makeText(this, "Please enter an id", Toast.LENGTH_LONG).show();
              return;
          }
          loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
  
          String url = Config.DATA_URL+editTextId.getText().toString().trim();
  
          StringRequest stringRequest = new StringRequest(url, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  loading.dismiss();
                  showJSON(response);
              }
          },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          Toast.makeText(MainActivity.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
                      }
                  });
  
          RequestQueue requestQueue = Volley.newRequestQueue(this);
          requestQueue.add(stringRequest);
      }
  
      private void showJSON(String response){
          String name="";
          try {
              JSONObject jsonObject = new JSONObject(response);
              JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
              JSONObject data = result.getJSONObject(0);
              name = data.getString(Config.KEY_Name);
          } catch (JSONException e) {
              e.printStackTrace();
          }
          textViewResult.setText("Name:\t"+name);
      }
  
      @Override
      public void onClick(View v) {
          getData();
      }
  }
  </code></pre>
  
  <p><strong>Config class</strong></p>
  
  <pre><code>public class Config {
      public static final String DATA_URL = "myPhpURL";
      public static final String KEY_Name = "name";
      public static final String JSON_ARRAY = "result";
  }
  </code></pre>