无法使用android phone debug连接到本地主机

无法使用android phone debug连接到本地主机,android,Android,我很难从本地主机检索数据。我使用xampp。我想要的是显示从localhost到android phone listview的数据。这是我在网上找到的讨论localhost和android的基本代码。以下是片段: p public类数据库\u演示扩展ListActivity{ /**在首次创建活动时调用*/ @凌驾 创建时的公共void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); 字符串结果=null; Inpu

我很难从本地主机检索数据。我使用xampp。我想要的是显示从localhost到android phone listview的数据。这是我在网上找到的讨论localhost和android的基本代码。以下是片段:

p

public类数据库\u演示扩展ListActivity{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
字符串结果=null;
InputStream=null;
StringBuilder sb=null;
ArrayList nameValuePairs=新的ArrayList();
列表r=新的ArrayList();
试一试{
//http post
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://10.0.2.2/android_connect3/");
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
is=entity.getContent();
}
捕获(例外e){
Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show();
}
//将响应转换为字符串
尝试
{
BufferedReader=新的BufferedReader(新的InputStreamReader(即“UTF-8”));
sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null)
{
sb.追加(第+行“\n”);
}
is.close();
结果=sb.toString();
}
捕获(例外e)
{
Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show();
}
//结束将响应转换为字符串
试一试{
JSONArray jArray=新JSONArray(结果);
JSONObject json_data=null;

对于(int i=0;i你必须检查这一行

HttpPost httppost = new HttpPost("http://10.0.2.2/android_connect3/");
改为

HttpPost httppost = new HttpPost("http://10.0.2.2/android_connect3/your_php_file_name");

你必须检查这条线

HttpPost httppost = new HttpPost("http://10.0.2.2/android_connect3/");
改为

HttpPost httppost = new HttpPost("http://10.0.2.2/android_connect3/your_php_file_name");

我知道了,我就是这么做的

    InputStream is;
    String result;

    StringBuilder sb;
    @Override
    public void onCreate(Bundle savedInstanceState) {

  }

我将它们声明为全局的,并删除空值作为对它们的赋值。

我得到了它。.我是这样做的

    InputStream is;
    String result;

    StringBuilder sb;
    @Override
    public void onCreate(Bundle savedInstanceState) {

  }

我将它们声明为全局的,并删除空值作为对它们的赋值

Im从localhost获取值Im从localhost获取值