E
E
Evgeny Kolman2016-10-25 16:50:14
Java
Evgeny Kolman, 2016-10-25 16:50:14

How to solve this problem: HostConnection::get() New Host Connection established?

package data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import Util.Utils;

/**
 * Created by Evgeny on 10/25/16.
 */

public class WeatherHttplClient {

    public String getWeatherData(String place){
        HttpURLConnection connection = null;
        InputStream inputStream = null;

        try {
            connection = (HttpURLConnection) (new URL(Utils.BASE_URL+place)).openConnection();
            connection.setRequestMethod("GET");
            connection.setDoInput(true);
            connection.connect();

            //Read the response
            StringBuffer stringBuffer = new StringBuffer();
            inputStream = connection.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = null;

            while ((line = bufferedReader.readLine()) != null) {
                stringBuffer.append(line + "\r\n");
            }

            inputStream.close();
            connection.disconnect();

            return stringBuffer.toString();

        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}

I'm learning to write for android, but there was a problem that an error occurs HostConnection::get() New Host Connection established 0xb2b858f0, tid 19733, when trying to create a connection.
d592366dea6c48c497499679a3b27a33.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Vishnevsky, 2016-11-03
@Tema_man

You have the wrong host. You are trying to reach www.google.byMinsk. Hence the error.
PS By the way, the error description begins further with the line: java.net.UnknownHostException...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question