NullPointerException异常的ItemizedOverlay.getIndexToDraw [英] NullPointerException in ItemizedOverlay.getIndexToDraw

查看:171
本文介绍了NullPointerException异常的ItemizedOverlay.getIndexToDraw的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个比较简单的MapActivity我试图让显示器 一个给定的地图区域内的营地的列表。我创建了一个自定义 OverlayItem的子类,称为CampOverlayItem,自定义 ItemizedOverlay称为CampsOverlay返回CampOverlayItems,和 当然是MapActivity子类,填充地图。

I have a relatively simple MapActivity that I'm trying to make display a list of "camps" within a given map region. I've created a custom subclass of OverlayItem called CampOverlayItem, a custom ItemizedOverlay called CampsOverlay that returns CampOverlayItems, and of course a MapActivity subclass that populates the map.

我是从使用的AsyncTask作为一个数据库中提取的叠加数据 在我的活动创造。所述的AsyncTask从触发 ViewTreeObserver.OnGlobalLayoutListener附连到的MapView

I'm pulling the overlay data from a database using an AsyncTask as created in my activity. The AsyncTask is triggered from a ViewTreeObserver.OnGlobalLayoutListener attached to the MapView.

在的AsyncTask的onPostExecute方法,我创建了一个新的实例 我CampsOverlay类和传递它返回营地的列表 数据库(这是在doInBackground取出)。然后,我打电话:

In the onPostExecute method of the AsyncTask, I create a new instance of my CampsOverlay class and pass it a list of the camps returned from the database (which are fetched in doInBackground). I then call:

mapView.getOverlays().add(newOverlay);

在这里newOverlay是我刚刚创建的CampsOverlay。所有这一切都code 运行没有错误,但是当试图地图绘制自身,我得到一个 NullPointerException异常与下面的堆栈跟踪:

where newOverlay is the CampsOverlay I just created. All of this code runs without error, but when the Map tries to draw itself, I get a NullPointerException with the following stack trace:

java.lang.NullPointerException
   at
com.google.android.maps.ItemizedOverlay.getIndexToDraw(ItemizedOverlay.java:
211)
   at
com.google.android.maps.ItemizedOverlay.draw(ItemizedOverlay.java:240)
   at com.google.android.maps.Overlay.draw(Overlay.java:179)
   at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:
42)
   at com.google.android.maps.MapView.onDraw(MapView.java:476)
   at android.view.View.draw(View.java:6274)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.View.draw(View.java:6277)
   at android.widget.FrameLayout.draw(FrameLayout.java:352)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.View.draw(View.java:6277)
   at android.widget.FrameLayout.draw(FrameLayout.java:352)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
   at android.view.View.draw(View.java:6277)
   at android.widget.FrameLayout.draw(FrameLayout.java:352)
   at com.android.internal.policy.impl.PhoneWindow
$DecorView.draw(PhoneWindow.java:1883)
   at android.view.ViewRoot.draw(ViewRoot.java:1332)
   at android.view.ViewRoot.performTraversals(ViewRoot.java:1097)
   at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4203)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
   at dalvik.system.NativeStart.main(Native Method)

由于它似乎特别重要,这里是code我 ItemizedOverlay子类:

Because it seems particularly relevant, here is the code for my ItemizedOverlay subclass:

public class CampsOverlay extends ItemizedOverlay<CampOverlayItem> {
    private ArrayList<Camp> camps = null;

    public CampsOverlay(Drawable defaultMarker, ArrayList<Camp> theCamps)
{
        super(defaultMarker);
        this.camps = theCamps;
    }

    @Override
    protected CampOverlayItem createItem(int i) {
        Camp camp = camps.get(i);
        CampOverlayItem item = new CampOverlayItem(camp);
        return item;
    }

    @Override
    protected boolean onTap(int index) {
        // TODO Auto-generated method stub
        return super.onTap(index);
    }

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

}

没有人有任何想法可能是发生在这里?我已经尝试 验证一切,我可以控制的非空。我可以 如果有必要提供更多的code。

Does anyone have any idea what could be happening here? I've attempted to verify that everything I have control over is non-null. I can provide more code if necessary.

推荐答案

我不知道你在哪里调用填充() CampsOverlay

I do not see where you are calling populate() on your CampsOverlay.

这里是显示覆盖项异步加载示例项目 - 也许它会给你一些想法,如果填充()不是问题。

Here is a sample project showing asynchronous loading of overlay items -- perhaps it will give you some ideas, if populate() is not the issue.

这篇关于NullPointerException异常的ItemizedOverlay.getIndexToDraw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆