我目前正在使用google-play-services库r3实现自己的 SupportMapFragment 子类。

当我尝试将Fragment添加到NullPointerExceptionActivity时,在库的内部类之一中得到ViewPager
这是相关的堆栈跟踪:

java.lang.NullPointerException
    at maps.y.p.onResume(Unknown Source)
    at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:115)
    at android.os.Binder.transact(Binder.java:310)
    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onResume(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment$a.onResume(Unknown Source)
    at com.google.android.gms.internal.c$1.a(Unknown Source)
    at com.google.android.gms.internal.c.a(Unknown Source)
    at com.google.android.gms.internal.c.onResume(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment.onResume(Unknown Source)
    at android.support.v4.app.Fragment.performResume(Fragment.java:1503)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
    at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:807)
    at android.support.v4.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManager.java:1112)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1461)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)

显然,内部映射此时为null。

有没有人遇到过这个问题并有解决方案?

最佳答案

在SupportMapFragment的子类中,您是否重写onCreateView(...)?

如果这样做,则还需要在自己的onCreateView(...)中调用super.onCreateView(...),以让父类(super class)创建其 View 。该片段与基础 View 紧密相关。

关于android - 子类化SupportMapFragment会导致NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13725056/

10-10 13:34