Android地图V2图形页面定制的片断内(NPE) [英] Android Maps V2 MapView inside custom fragment (NPE)

查看:136
本文介绍了Android地图V2图形页面定制的片断内(NPE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想使用或扩展 SupportMapFragment MapFragment 。我有我自己的基类,在这一堆code。

I do not want to use or extend SupportMapFragment or MapFragment. I have my own base class with a bunch of code in it.

该文件明确指出,当有人使用图形页面本身,所有相应的生命周期方法(的onCreate() onResume()等)应该被调用。

The documentation clearly states that when someone uses MapView by itself, all corresponding lifecycle methods (onCreate() onResume() etc.) should be called.

大多数在片段的生命周期方法类似于活动但是当我来​​回切换之间我的片段我最终能得到一个模糊NPE在的onDestroy() onResume()的方法。

Most of the lifecycle methods in a Fragment are similar to an Activity but when I switch back and forth between my Fragment I eventually get an obfuscated NPE in onDestroy() or in onResume() methods.

所有提供使用活动的样本图形页面而不是一个自定义的片段

All the samples provided use an Activity with a MapView but not a custom Fragment.

已经有人做过了吗?你能提供一个图形页面在自己的片段类样品code?

Has someone done that already? Can you provide sample code of a MapView in your own Fragmentclass?

推荐答案

我成功地在包括图形页面(V2)在自定义的片段本身嵌入在ViewPager。在我的情况下,图形页面包含在片段布局文件。我不得不呼吁MapView的生命周期方法(的onCreate()名为 onCreateView()从片段),并手动调用 MapsInitializer.initialize(上下文)来避免 NullPointerException异常从类BitmapDesc​​riptorFactory(获取位图标记)。最后这招很奇怪,我不知道为什么地图系统未正确初始化本身没有这个电话,也许是在目前的版本只是一个错误...

I succeeded in including a MapView (v2) in a custom Fragment itself embedded in a ViewPager. In my case, the MapView is included in the Fragment layout file. I have had to call lifecycle methods on MapView (onCreate() called onCreateView() from the Fragment), and to call manually MapsInitializer.initialize(context) to avoid a NullPointerException from class BitmapDescriptorFactory (to get the bitmap for markers). This last trick is strange, and I don't know why the Map system isn't properly initialized itself without this call, maybe it's just a bug in the current version ...

在我来说,我还没有得到任何 NullPointerException异常 onResume()的onDestroy()

In my case I haven't had any NullPointerException in onResume() or onDestroy().

这篇关于Android地图V2图形页面定制的片断内(NPE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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