2012-03-30 54 views
2

您好我想創造一個我想改變列表accorfing來選擇這樣的位置我寫了一個覆蓋類IllegalStateException異常目標不能爲空

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目標主機不能爲空並在參數中設置請幫助如何解決此錯誤。 這裏是錯誤的日誌貓

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' 
+0

請問您可以發佈整個錯誤日誌,以便我能理解... – 2012-03-30 06:38:33

回答

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

感謝您的回覆 – 2012-03-30 07:49:56

+0

現在的工作。 – 2012-03-30 07:50:06

+6

工作?它是如何工作的,你在做什麼? – meh 2012-10-17 13:42:53

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

請給出一些Java代碼行如何編碼此網址,以便我將得到我的JSON數據。在瀏覽器上顯示正確的json數據的網址。 – 2012-03-30 06:46:51

+0

在答案中增加一個例子 – 2012-03-30 08:07:51

相關問題