2012-10-17 31 views
3

我在ICS上得到這個異常,而在2.2上運行正常。Http get exception目標主機在ICS上不能爲空

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); 
+0

你可以發佈requestUrl嗎?它似乎沒有適當的格式。 – kosa

+0

http://maps.googleapis.com/maps/api/geocode/json?latlng=32.0692342,34.7952296&sensor=true – meh

回答

9

取出URLEncoder.encode調用,它不需要

這是需要編碼的URL參數,例如:

String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+URLEncoder.encode("32.0692342,34.7952296")+"&sensor="+URLEncoder.encode("true") 
+0

但是如果我之前需要對網址進行編碼呢? 10-17 16:29:53.235:W/System.err(18170):java.net.URISyntaxException:索引58處的查詢中存在非法字符:http://maps.googleapis.com/maps/api/geocode/json ?address =,בדיקה,&sensor = true – meh

+4

您只需要編碼URL參數,而不是整個網址 –

相關問題