title: Android fetch data from mySql
body: <p>I have to get some data from a MySQL database on server. I have the following code.but the app crashes when I run it. I also get the <em>Permission denied (missing INTERNET permission?)</em> in my Logcat even though I specified the internet permission in my Android Manifest.
  Any idea what might be wrong here?</p>
  
  <p>Java file</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.os.StrictMode;
  import android.util.Log;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.methods.HttpGet;
  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 java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  public class MainActivity extends Activity {
  
      TextView text;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
  
          connect();
      }
      private void connect() {
          String data;
          List&lt;String&gt; r = new ArrayList&lt;String&gt;();
          ArrayAdapter&lt;String&gt;adapter=new ArrayAdapter&lt;String&gt;(getApplicationContext(), android.R.layout.simple_list_item_1,r);
          ListView list=(ListView)findViewById(R.id.listView1);
          try {
              DefaultHttpClient client = new DefaultHttpClient();
              HttpGet request = new HttpGet("http://xxxxx/data.php");
              HttpResponse response = client.execute(request);
              HttpEntity entity=response.getEntity();
              data=EntityUtils.toString(entity);
              Log.e("STRING", data);
  
              try {
  
                  JSONArray json=new JSONArray(data);
                  for(int i=0;i&lt;json.length(); i++)
                  {
                      JSONObject obj=json.getJSONObject(i);
                      String name=obj.getString("name");
                      String desc=obj.getString("description");
                     // String lat=obj.getString("lat");
                      Log.e("STRING", name);
                      r.add(name);
                      r.add(desc);
                    //  r.add(lat);
                      list.setAdapter(adapter);
  
                  }
  
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
          } catch (ClientProtocolException e) {
              Log.d("HTTPCLIENT", e.getLocalizedMessage());
          } catch (IOException e) {
              Log.d("HTTPCLIENT", e.getLocalizedMessage());
          }
  
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.diana.menu" &gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>data.php</p>
  
  <pre><code>&lt;?php
  $conn=mysql_connect('localhost', 'xxxx', 'xxxxx','u199776286_pois');
  
  if(!$conn )
  {
    die('Could not connect: ' . mysql_error());
  }
  
  $sql = 'SELECT name, description FROM pois';
  
  mysql_select_db('u199776286_pois');
  $retval = mysql_query( $sql, $conn );
  
  if(! $retval )
  {
    die('Could not get data: ' . mysql_error());
  }
  while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
  {
      echo "NAME : {$row['name']} &lt;br&gt; ".
           "DESCRIPTION : {$row['description']} &lt;br&gt; ".
           "--------------------------------&lt;br&gt;";
  } 
  echo "Fetched data successfully\n";
  mysql_close($conn);
  
  
  ?&gt;
  </code></pre>
  
  <p>my logcat
  <img src="https://i.stack.imgur.com/9htI8.png" alt="enter image description here"></p>