在尝试将mapfragment加载到寻呼机视图时,我得到以下堆栈跟踪,它从不指出我的代码。
我甚至不知道从哪里开始解决这个问题,想法?
FATAL EXCEPTION: main
Process: com.app, PID: 21938
java.lang.NullPointerException: Attempt to invoke interface method 'void maps.ei.bz.o()' on a null object reference
at maps.ei.n.b(Unknown Source)
at com.google.android.gms.maps.internal.i$a.onTransact(:com.google.android.gms.alldynamite:115)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onResume(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zza.onResume(Unknown Source)
at com.google.android.gms.dynamic.zza$7.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onResume(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onResume(Unknown Source)
at android.support.v4.app.Fragment.performResume(Fragment.java:2020)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1107)
at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:926)
at android.support.v4.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManager.java:1276)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1634)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:2035)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737)
at android.app.Activity.dispatchTouchEvent(Activity.java:2771)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364)
at android.view.View.dispatchPointerEvent(View.java:9520)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
答案 0 :(得分:0)
我怀疑在初始化GoogleMap之前,在MapView上调用onResume()。
要避免此问题,请确保在创建SupportMapFragment时,然后在其上调用getMapAsync(),并且在触发OnMapReadyCallback()之前不要将该片段添加到寻呼机视图中。
e.g。当您创建MapFragment时:
SupportMapFragment mapFragment = (SupportMapFragment) getActivity()
.getSupportFragmentManager().findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(onMapReadyCallback);
然后在回调中:
OnMapReadyCallback onMapReadyCallback = new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
addFragmentToPagerView();
}
};