title: Android Studio error org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
body: <p>I have Android Studio with wamp server. I am trying to use a php file to access MySql database on phpmyadmin. I have tried the emulator and Android Device. I am always getting this error : </p>
  
  <pre><code>org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
  </code></pre>
  
  <p>This is my MainActivity.jav file</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  private TextView responseTView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      this.responseTView = (TextView) findViewById(R.id.response);
  
      new getDetails().execute(new SqlConnector());
  }
  
  private void setTextToTextView(JSONArray jsonArray) {
      String s = "";
      for(int i=0; i&lt;jsonArray.length();i++) {
          JSONObject obj = null;
          try {
              obj = jsonArray.getJSONObject(i);
              s = s + "ID: " + obj.getString("id") + "Customer Name:" + obj.getString("Customer");
          }
          catch(JSONException e) {
              e.printStackTrace();
          }
      }
      this.responseTView.setText(s);
  }
  
  private class getDetails extends AsyncTask&lt;SqlConnector,Long,JSONArray&gt; {
  
      @Override
      protected JSONArray doInBackground(SqlConnector... params) {
         return params[0].getDetailsinJson();
      }
      @Override
      protected void onPostExecute(JSONArray jsonArray) {
       setTextToTextView(jsonArray);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And this is my SqlConnector.java file</p>
  
  <pre><code>public class SqlConnector {
  public JSONArray getDetailsinJson() {
      String url = "http://10.0.2.2:8080/D:/Database/main1.php";
  
      HttpEntity httpEntity = null;
  
      try {
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpGet httpGet = new HttpGet(url);
          Log.d("This is inside HTTP try block.","No error..");
          HttpResponse httpResponse  = httpClient.execute(httpGet); //Using Logs, it's this line that brings on the error. That's my understanding.
  
          httpEntity=httpResponse.getEntity();
  
      }
      catch(ClientProtocolException e) {
          e.printStackTrace();
      }
      catch (IOException e) {
          e.printStackTrace();
      }
      Log.d("Inside SqlConnector Class", "ajsdhlk");
      JSONArray jsonArray = null;
      if(httpEntity != null) {
          try {
              String response= EntityUtils.toString(httpEntity);
              Log.e("This is the response", response);
              jsonArray = new JSONArray(response);
          }
          catch(JSONException e) {
              Log.d("This is inside Catch block.","Error in JSONArray");
              e.printStackTrace();
          }
          catch(IOException e) {
              Log.d("This is inside catch block.","IOException");
              e.printStackTrace();
              }
      }
      return jsonArray;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have read many posts on Stackoverflow over similar problems. But, I am not able to get past this error after trying many things. I tried changing the IP I have used but it doesn't help. Please help.
  I am quite new to Android Studio, so please explain the solutions. Thanks a lot for help.</p>