您好,我想创建一个活动,在该活动中,我想根据所选位置更改列表的内容,因此我编写了一个覆盖类

class MapOverlay extends com.google.android.maps.Overlay
        {
            @Override
            public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
            {
                super.draw(canvas, mapView, shadow);

                //---translate the GeoPoint to screen pixels---
             return false;
            }

            @Override
            public boolean onTouchEvent(MotionEvent event, MapView mapView)
            {
                //---when user lifts his finger---
                if (event.getAction() == 1) {
                    GeoPoint p = mapView.getProjection().fromPixels(
                        (int) event.getX(),
                        (int) event.getY());

                           double x = p.getLatitudeE6() / 1E6 ;
                           double y= p.getLongitudeE6() /1E6 ;
                           String url="http://api.v3.factual.com/t/global?geo={\"$circle\":{\"$center\":["+x+","+y+"],\"$meters\":5000}}&KEY=uZSowx1CRS4oD2R8kQGGgjkbFoDMHlriDl1IAoQc";
                      url=URLEncoder.encode(url);
                           HttpGet get=new HttpGet(url);
                          try {
                            HttpResponse response=client.execute(get);
                        Log.i("hello",EntityUtils.toString(response.getEntity()));
                        } catch (ClientProtocolException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                }
                return true;
            }
        }


但是当我单击任何项​​目时,它显示我被强制关闭并显示错误
Java.lang.IllegalStateException目标主机不得为null,并且在参数中进行设置,请帮助解决该错误。
这是错误的日志猫

03-30 12:30:52.267: E/AndroidRuntime(692): Uncaught handler: thread main exiting due to uncaught exception
03-30 12:30:52.277: E/AndroidRuntime(692): java.lang.IllegalStateException: Target host must not be null, or set in parameters.
03-30 12:30:52.277: E/AndroidRuntime(692):  at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:561)
03-30 12:30:52.277: E/AndroidRuntime(692):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)
03-30 12:30:52.277: E/AndroidRuntime(692):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-30 12:30:52.277: E/AndroidRuntime(692):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-30 12:30:52.277: E/AndroidRuntime(692):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
03-30 12:30:52.277: E/AndroidRuntime(692):  at factual.box.android.Factual_Mapping$MapOverlay.onTouchEvent(Factual_Mapping.java:91)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.google.android.maps.MapView.onTouchEvent(MapView.java:625)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.View.dispatchTouchEvent(View.java:3709)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.os.Looper.loop(Looper.java:123)
03-30 12:30:52.277: E/AndroidRuntime(692):  at android.app.ActivityThread.main(ActivityThread.java:4363)
03-30 12:30:52.277: E/AndroidRuntime(692):  at java.lang.reflect.Method.invokeNative(Native Method)
03-30 12:30:52.277: E/AndroidRuntime(692):  at java.lang.reflect.Method.invoke(Method.java:521)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-30 12:30:52.277: E/AndroidRuntime(692):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-30 12:30:52.277: E/AndroidRuntime(692):  at dalvik.system.NativeStart.main(Native Method)
03-30 12:30:52.297: I/dalvikvm(692): threadid=7: reacting to signal 3
03-30 12:30:52.317: I/dalvikvm(692): Wrote stack trace to '/data/anr/traces.txt'

最佳答案

不编码,请使用以下代码。

         String url = "http://api.v3.factual.com/t/global?KEY=uZSowx1CRS4oD2R8kQGGgjkbFoDMHlriDl1IAoQc";
        HttpParams params = new BasicHttpParams();
        params.setParameter("geo", "{\"$circle\":{\"$center\":[\" + x + \",\" + y + \"],\"$meters\":5000}}");
        HttpGet get = new HttpGet(url);

10-06 06:53