且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android 地图 NullPointerException ItemizedOverlay

更新时间:2023-11-16 16:22:28

其实问题不在你的ItemizedOverlay的实现上,而在你的MapActivity的实现上.从类似的堆栈跟踪此处中可以看出,在第 42 行,OverlayBundle 正在调用 draw() 方法的叠加.这指向您添加到 mapView 某处的空 Overlay.

Actually the problem is not in the implementation of your ItemizedOverlay, but in the implementation of your MapActivity. As you can see from a similar stack trace here at line 42 the OverlayBundle is calling the draw() method of an Overlay. This points to a null Overlay that you added to your mapView somewhere.

一些有用的提示:您绝对应该通过取消注释您已经在那里的第一行代码将 drawable 传递给您的超级构造函数(用于命中测试):

Some helpful hints: You should definitely pass a drawable to your super constructor (used of hit-testing) by uncommenting the first line of code you already have in there:

     public SitesOverlay() {

        //super(null);
        super(boundCenter(defaultMarker));
        //items = getMainOverlayArray();
        //items = mOverlays;
        populate();

    }

并且可能不会在 draw() 方法中调用 super.draw().

and potentially not call super.draw() in your draw() method.

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        // why do you do this if you paint it yourself later on.
        super.draw(canvas, mapView, false

很可能您实际上必须两者都做.

Most likely you will have to actually do both.

想想看,您绝对应该将 drawable 传递给您的超级构造函数,因为它用于命中测试.修改了上面的文字以反映这一点.

Come to think of it you should definitely pass a drawable to your super constructor as it is used for hit-testing. Amended the text above to reflect that.