4

我在 ICS 上遇到了这个异常,而在 2.2 上它运行良好。

java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://maps.googleapis.com/maps/api/geocode/json?latlng=32.0692342,34.7952296&sensor=true

这是我的代码:

        HttpGet request = new HttpGet(URLEncoder.encode(requestUrl, "UTF-8"));
        HttpResponse response;
        response = mHttpClient.execute(request);
4

1 回答 1

10

Remove the URLEncoder.encode call, it is not needed

It is needed to encode the url parameters, for example:

String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+URLEncoder.encode("32.0692342,34.7952296")+"&sensor="+URLEncoder.encode("true")
于 2012-10-17T14:25:48.277 回答