我在活動中使用mapview,但我收到一個奇怪的空指針異常,我似乎無法找到原因。Android:奇怪的在MapView onDestroy內的活動
XML:
<com.google.android.gms.maps.MapView
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/myMapView"
android:layout_width="match_parent"
android:layout_height="156dp"
map:cameraZoom="16"
map:liteMode="true"
android:visibility="invisible"
/>
那麼活動中:
private MapView mMapView;
初始化中的onCreate:
mMapView = (MapView) findViewById(R.id.myMapView);
和重寫方法:
mMapView.onCreate(savedInstanceState);
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}
而且我不斷地在MapView類的onDestroy方法,其堆棧跟蹤如下接收崩潰:
java.lang.RuntimeException: Unable to destroy activity {myActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.LinkedList.isEmpty()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3831)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.LinkedList.isEmpty()' on a null object reference
at com.google.android.gms.dynamic.zza.zzeJ(Unknown Source)
at com.google.android.gms.dynamic.zza.onDestroy(Unknown Source)
at com.google.android.gms.maps.MapView.onDestroy(Unknown Source)
at myActivity.onDestroy(myActivity.java:454)
at android.app.Activity.performDestroy(Activity.java:6422)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
鑑於mmapview在的onCreate從XML開始初始化並存在罰款,直到的onDestroy,這個空指針的原因是什麼?
如果你刪除'super.onDestroy();'或者在下面移動這行? –
@ShreeKrishna有趣的想法 - 我會嘗試。謝謝! – Jon
不幸的是,崩潰仍然發生 – Jon