私はアクティビティ内でmapviewを使用していますが、原因を特定できないような奇妙なnullポインタ例外を受け取りました。Android:MapView onDestroyの奇妙なnpeアクティビティ内
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"
/>
そして活性内側:のonCreateで
private MapView mMapView;
初期化:
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メソッドでクラッシュを受けています:、mmapviewは、XMLからのonCreateの開始時に初期化され、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)
このnullポインタの原因は何ですか?
'super.onDestroy();'を削除するか、この行を下に移動するとどうなりますか? –
@ShreeKrishna面白いアイデア - 私はそれを試してみましょう。ありがとう! – Jon
残念ながら、クラッシュはまだ発生します – Jon