2013-03-27 173 views
0

我在自己的應用上使用了Google地圖API版本1,並在上面添加了自定義重疊項。問題是,在很多場合我遇到崩潰和強制關閉應用程序,我很確定它是由地圖引起的。我檢查了線程,我意識到我需要使用populate()函數。谷歌地圖API崩潰

的問題是我不知道在哪裏使用它究竟是因爲代碼是不是我最初寫:(。

03-27 10:53:09.440: E/InputEventReceiver(28709): Exception dispatching input event. 
03-27 10:53:09.440: E/MessageQueue-JNI(28709): Exception in MessageQueue callback:  handleReceiveCallback 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): java.lang.NullPointerException 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at com.google.android.maps.MapView.onTouchEvent(MapView.java:681) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.View.dispatchTouchEvent(View.java:7337) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2410) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2145) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2117) 
03-27 10:53:09.490: E/MessageQueue-JNI(28709): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416) 

這裏是我的逐項覆蓋類,這是造成麻煩

public class AdvrItemizedOverlay extends ItemizedOverlay<MapOverlayItem> { 

protected Vector<AdvrMapItem> mOverlayItems = new Vector<AdvrMapItem>(); 

protected Bitmap mEmptyMarker = null; 

protected Resources mResources = null; 

protected Rect mDstRect = new Rect(6, 6, 66, 66); 

public AdvrItemizedOverlay(Resources res) { 
    super(boundCenterBottom(res.getDrawable(R.drawable.bg_map_mark_adver))); 
    mEmptyMarker = BitmapFactory.decodeResource(res, R.drawable.bg_map_mark_adver); 
    float density = (float)mEmptyMarker.getWidth()/72.0f; 
    mDstRect.left *= density; 
    mDstRect.top *= density; 
    mDstRect.right *= density; 
    mDstRect.bottom *= density; 
    mResources = res; 
    performPopulated(); 
} 

@Override 
protected MapOverlayItem createItem(int i) { 
    AdvrMapItem advrItem = mOverlayItems.get(i); 
    MapOverlayItem overlayItem = advrItem.overlayItem(); 
    Drawable marker = advrItem.mapMarker(mResources, mEmptyMarker, mDstRect); 
    if (marker != null) 
     overlayItem.setMarker(boundCenterBottom(marker)); 
    return overlayItem; 

} 

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

public void add(AdvrMapItem userItem) { 
    mOverlayItems.add(userItem); 
    populate(); 
} 

public void remove(AdvrMapItem item) { 
    mOverlayItems.remove(item); 
    setLastFocusedIndex(-1); 
    populate(); 
} 

public void clear() { 
    mOverlayItems.removeAllElements(); 
    setLastFocusedIndex(-1); 
    populate(); 
} 

public void performPopulated() { populate(); } 

}

我不知道到底時,構造函數被調用和放置位置填入方法。感謝所有

回答

0

你在某個點向它傳遞了一個空標記。你需要找出在哪裏。您可能還想考慮更新 - 不僅版本2中的API更簡單,而且它們不再提供新的v1 api密鑰/