IllegalStateException目标不能为null

时间:2012-03-30 06:09:42

标签: android android-widget

嗨我想创建一个活动,我想在其中更改所选位置的列表内容,所以我写了一个叠加类

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目标Host不能为null并在参数中设置请帮助如何解决此bug。 这是错误的日志猫

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'

2 个答案:

答案 0 :(得分:0)

您编码了“http://”,因此您的网址无效 尝试使用类似的东西

String geoData=URLEncoder.encode("{\"$circle\":{\"$center\":["+x+","+y+"],\"$meters\":5000}}");  
String key = "uZSowx1CRS4oD2R8kQGGgjkbFoDMHlriDl1IAoQc";  
String urlPattern  ="http://api.v3.factual.com/t/global?geo=%s&KEY=%s";  
String url = String.format(urlPattern, geoData,key);  

答案 1 :(得分:0)

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

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