谷歌地图API崩溃

时间:2013-03-27 02:59:53

标签: android google-maps nullpointerexception itemizedoverlay

我在我的应用上使用google maps API的第1版,并在顶部自定义重叠。问题是,在很多场合我都遇到了应用程序崩溃和强行关闭,我很确定它是由地图引起的。我检查了线程,我意识到我需要使用populate()函数。

问题是我不确定在哪里使用它,因为代码最初不是由我编写的:(。

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

}

我不确定何时调用构造函数以及放置populate方法的位置。谢谢所有

1 个答案:

答案 0 :(得分:0)

你在某个时候传递了一个空标记。你需要找出原因。您可能还需要考虑更新 - 不仅版本2中的API更简单,而且它们不再发布新的v1 api密钥/