2012-08-27 16 views
0

我正在這個錯誤wn我在地圖上的搜索位置圖標觸摸...我有3個位置。 2位置r我的位置&客戶位置&我有搜索editbox.when我搜索的位置,它顯示d圖標在正確的位置,但wn我觸摸該圖標將迫使關閉...我必須得到對話。 這裏是我的代碼 Can anyone guide me how to get Google Directions between two locations using JSON我得到這個錯誤,當我點擊搜索位置圖標

plz幫助我的任何一個預先感謝

08-27 17:52:52.708: D/AndroidRuntime(3721): Shutting down VM 
08-27 17:52:52.708: W/dalvikvm(3721): threadid=1: thread exiting with uncaught exception (group=0x40be71f8) 
08-27 17:52:52.723: E/AndroidRuntime(3721): FATAL EXCEPTION: main 
08-27 17:52:52.723: E/AndroidRuntime(3721): java.lang.NullPointerException 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.app.AlertDialog$Builder.<init>(AlertDialog.java:359) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.androidhive.googleplacesandmaps.AddItemizedOverlay.onTap(AddItemizedOverlay.java:74) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.google.android.maps.MapView.onTouchEvent(MapView.java:683) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.View.dispatchTouchEvent(View.java:5588) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2060) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1398) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.app.Activity.dispatchTouchEvent(Activity.java:2364) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2008) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.View.dispatchPointerEvent(View.java:5768) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2911) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2485) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:852) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2494) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.os.Looper.loop(Looper.java:137) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at android.app.ActivityThread.main(ActivityThread.java:4514) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at java.lang.reflect.Method.invoke(Method.java:511) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
08-27 17:52:52.723: E/AndroidRuntime(3721):  at dalvik.system.NativeStart.main(Native Method) 
08-27 17:52:59.911: I/Process(3721): Sending signal. PID: 3721 SIG: 9 

Placesmapactivity.java

以上TR是我在 FUL代碼的鏈接只是去這個方法快速參考..

 @Override 
      public void onClick(View v) {   
       String usrLoc = autoCompletetextView.getText().toString(); 
       Geocoder gc = new Geocoder(PlacesMapActivity.this); 

       try { 
        addr=gc.getFromLocationName(usrLoc, 3);//maximum 2 results 
        if(addr.size()>0){ 
         address=addr.get(0);//get the first result 
         convertLongi=address.getLongitude(); 
         convertLati=address.getLatitude(); 
         geopointsearch = new GeoPoint((int)(convertLati * 1E6), (int)(convertLongi * 1E6));          

        // Map geopointsearch overlay item 
         itemizedOverlay2 = new AddItemizedOverlay(drawable_client);  
         overlayitem = new OverlayItem(geopointsearch, "Your Location2", "I am ur client!"); 
         itemizedOverlay2.addOverlay(overlayitem);  
         mapOverlays.add(itemizedOverlay2); 
         itemizedOverlay2.populateNow(); 
         mc.animateTo(geopointsearch); 
        // mc.zoomIn(); 
        } 

       } catch (IOException e) {     
        e.printStackTrace(); 
       } 
      }         
     }); 

    // Map overlay item 
    itemizedOverlay = new AddItemizedOverlay(drawable_user, this); 
    overlayitem = new OverlayItem(geoPoint, "Your Location","That is you!"); 
    itemizedOverlay.addOverlay(overlayitem);   
    mapOverlays.add(itemizedOverlay); 
    itemizedOverlay.populateNow();  
    // Map client overlay item 
    itemizedOverlay1 = new AddItemizedOverlay(drawable_client, this);  
    overlayitem1 = new OverlayItem(geoPoint1, "Your Location2", "I am ur client!"); 
    itemizedOverlay1.addOverlay(overlayitem1);    
    mapOverlays.add(itemizedOverlay1); 
    itemizedOverlay1.populateNow(); 
    // Map near overlay item  
    itemizedOverlay = new AddItemizedOverlay(drawable, this); 
    // Map geopointsearch overlay item 
    /* itemizedOverlay2 = new AddItemizedOverlay(drawable_client, this);  
    overlayitem2 = new OverlayItem(geopointsearch, "Your Location3", "ur searching for me!"); 
    itemizedOverlay2.addOverlay(overlayitem2);  
    mapOverlays.add(itemizedOverlay2); 
    itemizedOverlay2.populateNow();*/ 

AddItemizedOverlay.java

公共類AddItemizedOverlay擴展ItemizedOverlay {

private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>(); 

    private Context context; 
    MapController mc; 
Drawable drawable; 

private GeoPoint geopoint; 



public AddItemizedOverlay(Drawable defaultMarker) { 
     super(boundCenterBottom(defaultMarker)); 
    } 

    public AddItemizedOverlay(Drawable defaultMarker, Context context) { 
     this(defaultMarker); 
     this.context = context; 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    { 
     if (event.getAction() == 1) { 
      GeoPoint geopoint = mapView.getProjection().fromPixels(
       (int) event.getX(), 
       (int) event.getY()); 
      // latitude 
      double lat = geopoint.getLatitudeE6()/1E6; 
      // longitude 
      double lon = geopoint.getLongitudeE6()/1E6; 

     // Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show(); 
     }  
     return false; 
    } 


@Override 
    protected OverlayItem createItem(int i) { 
     return mapOverlays.get(i); 
    } 

    @Override 
    public int size() { 
     return mapOverlays.size(); 
    } 

    @Override 
    protected boolean onTap(int index) { 
    OverlayItem item = mapOverlays.get(index); 
    AlertDialog.Builder dialog = new AlertDialog.Builder(this.context); 
    dialog.setTitle(item.getTitle()); 
    dialog.setMessage(item.getSnippet()); 
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
     } 
    }); 
    dialog.show(); 
    return true; 
    } 

    public void addOverlay(OverlayItem overlay) { 
     mapOverlays.add(overlay); 
    } 

    public void populateNow(){ 
     this.populate(); 
    } 

} 

回答

0

嘗試改變保護布爾中的onTap(INT指數)如下:

@Override 
protected boolean onTap(int index) { 
OverlayItem item = mapOverlays.get(index); 
AlertDialog.Builder dialog = new AlertDialog.Builder(this.context); 
dialog.setTitle(item.getTitle()); 
dialog.setMessage(item.getSnippet()); 
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
    } 
}); 
AlertDialog alertDialog=dialog.create(); 
alertDialog.show(); 
return true; 

}

您需要從創建AlertDialog DialogBu​​ilder。

+0

嗨Eldhose M巴布,在這裏我geting錯誤。 AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);仍然我geting相同的錯誤... plz幫助我.. –

+0

嗨,,我得到以上錯誤任何人都可以幫助我.. ..對話框顯示正確的1.//地圖覆蓋項目2.//地圖客戶端覆蓋項目你可以參考上面的代碼..它顯示的錯誤在 3.//地圖geopointsearch覆蓋項目...它正在搜索正確的位置,圖像也顯示,但在警報對話框中的錯誤,當我觸摸它的圖像顯示以上錯誤。 PLZ說我錯誤的傢伙..提前感謝。 –

+0

簽到Placesmapactivity.java代碼 –

相關問題