Category Archives: android-internet

connection to http server refused

Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to refused Error converting result java.lang.NullPointerException: lock == null

I am getting the above error when i try to connect my emulator/device to my server. I am able to access this url from my browser, but unable to access it from my device or my emulator. I have read other questions relating to this topic but haven't found the solution anywhere. I have added internet permission in my manifest and I'm using a Xampp server.

This is my android code for the network call:

            String result = "";
            InputStream is = null;
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            final String statd = db.getUserOnline("id");
            nameValuePairs.add(new BasicNameValuePair("id1",id));
            nameValuePairs.add(new BasicNameValuePair("status", statd));
            Log.e("innetwork","innetwork thread");
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
            }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
            //convert response to string
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");


Please help me. Iam a beginner in android.