Android Studio error org.apache.http.conn.HttpHostConnectExc


Android Studio error org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused

我有带有wamp服务器的Android Studio。我正在尝试使用php文件访问phpmyadmin上的MySql数据库。我已经尝试了模拟器和安卓设备。我总是收到此错误:

org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused

这是我的 MainActivity.jav 文件

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<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<SqlConnector,Long,JSONArray> {
    @Override
    protected JSONArray doInBackground(SqlConnector... params) {
       return params[0].getDetailsinJson();
    }
    @Override
    protected void onPostExecute(JSONArray jsonArray) {
     setTextToTextView(jsonArray);
    }
}

}

这是我的 SqlConnector.java 文件

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;
}

}

我已经阅读了许多关于Stackoverflow的类似问题的帖子。但是,在尝试了很多事情后,我无法克服此错误。我尝试更改我使用的 IP,但没有帮助。请帮忙。我对Android Studio很陌生,所以请解释解决方案。非常感谢您的帮助。

在尝试了很多选项几个小时之后。我更改了服务器。我使用在线网络托管网站来存储我的文件。而且,这以某种方式阻止了此错误。如果您认为还有其他出路,要使用 wamp,请告诉我。

我设法通过在 url 中从 cmd -> ipconfig 写入我的 IP 地址来解决此问题:

字符串网址 ="http://192.168.x.x/D:/Database/main1.php";