java.lang.IllegalArgumentException

在获得JSON数据时发生如下异常:

12-30 22:38:24.560: E/AndroidRuntime(29341): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 57: http://maps.google.com/maps/api/geocode/json?address=*;df
12-30 22:38:24.560: E/AndroidRuntime(29341): &sensor=false
12-30 22:38:24.560: E/AndroidRuntime(29341): at java.net.URI.create(URI.java:970)
12-30 22:38:24.560: E/AndroidRuntime(29341): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
12-30 22:38:24.560: E/AndroidRuntime(29341): at com.c35.mtd.calendar.activity.MemoViewActivity.getLocationInfo(MemoViewActivity.java:442)
12-30 22:38:24.560: E/AndroidRuntime(29341): at com.c35.mtd.calendar.activity.MemoViewActivity.locationPos(MemoViewActivity.java:414)
12-30 22:38:24.560: E/AndroidRuntime(29341): at com.c35.mtd.calendar.activity.MemoViewActivity$LocationPositionTask.doInBackground(MemoViewActivity.java:392)
12-30 22:38:24.560: E/AndroidRuntime(29341): at com.c35.mtd.calendar.activity.MemoViewActivity$LocationPositionTask.doInBackground(MemoViewActivity.java:1)

 

代码:

HttpGet httpGet = new HttpGet("http://maps.google."
  + "com/maps/api/geocode/json?address=" + address
  + "&sensor=false");

 

原因是输入的address中还有换行符号, 在使用address之前将换行符号去掉。

String add = address.replace("\r", ""); 
add = address.replace("\n", "");

你可能感兴趣的:(exception)