Unable to connect to localhost using android phone debug
<p>Im having a hard time retrieving the data from my localhost. I use xampp. What i want is to display the data from localhost to android phone listview. This is the basic code i found in the net that discuss about localhost and android. here is the snippet:</p>

<p>p</p>

<pre><code>ublic class Database_demo extends ListActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        String result = null;
        InputStream is = null;
        StringBuilder sb = null;
        ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
        List&lt;String&gt; r = new ArrayList&lt;String&gt;();

        try{

        //http post
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2/android_connect3/");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        }
        catch(Exception e){
            Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
       }

        //Convert response to string  
        try
        {
          BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));

          sb = new StringBuilder();

          String line = null;

          while ((line = reader.readLine()) != null) 
          {
             sb.append(line + "\n");
          }

          is.close();

          result = sb.toString();
        }
        catch(Exception e)
        {
            Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
        }
        //END Convert response to string   
        try{
                JSONArray jArray = new JSONArray(result);
                JSONObject json_data=null;
                for(int i=0;i&lt;jArray.length();i++)
                {
                   json_data = jArray.getJSONObject(i);
                   r.add(json_data.getString("reg"));
               }
               setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_expandable_list_item_1, r));
            }
            catch(JSONException e1){
                Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
            } catch (ParseException e1) {
                Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
        }

    }
}
</code></pre>

<p>And here is my PHP file:</p>

<pre><code>&lt;?php
mysql_connect('localhost','root','');
mysql_select_db('android_sql');
$sql = "select * from reg";
$query = mysql_query($sql);

while($row = mysql_fetch_assoc($query)){
$output[] = $row;
}
print (json_encode($output));
mysql_close();


?&gt;
</code></pre>

<p>And this is my exception:
                  <a href="http://pastebin.com/QZkfG0bp" rel="nofollow">http://pastebin.com/QZkfG0bp</a></p>
