我的應用程序顯示mapfragment並在其上繪製少量標記。 當我在真機上運行,everithing是好的,但是當我使用AVD模擬器或Genymotion模擬器我有這種類型的錯誤(來自logcat中)的:在設備上測試ok,在模擬器上NULLPOINTER
06-18 11:51:02.743: E/AndroidRuntime(1825): FATAL EXCEPTION: main
06-18 11:51:02.743: E/AndroidRuntime(1825): java.lang.RuntimeException: Unable to resume activity {com.flex.sklepik/com.flex.sklepik.ReadComments}: java.lang.NullPointerException
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.os.Looper.loop(Looper.java:130)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-18 11:51:02.743: E/AndroidRuntime(1825): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 11:51:02.743: E/AndroidRuntime(1825): at java.lang.reflect.Method.invoke(Method.java:507)
06-18 11:51:02.743: E/AndroidRuntime(1825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-18 11:51:02.743: E/AndroidRuntime(1825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-18 11:51:02.743: E/AndroidRuntime(1825): at dalvik.system.NativeStart.main(Native Method)
06-18 11:51:02.743: E/AndroidRuntime(1825): Caused by: java.lang.NullPointerException
06-18 11:51:02.743: E/AndroidRuntime(1825): at com.flex.sklepik.ReadComments.wczytajMape(ReadComments.java:423)
06-18 11:51:02.743: E/AndroidRuntime(1825): at com.flex.sklepik.ReadComments$LoadComments.onPreExecute(ReadComments.java:299)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.os.AsyncTask.execute(AsyncTask.java:391)
06-18 11:51:02.743: E/AndroidRuntime(1825): at com.flex.sklepik.ReadComments.onResume(ReadComments.java:160)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.Activity.performResume(Activity.java:3832)
06-18 11:51:02.743: E/AndroidRuntime(1825): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
06-18 11:51:02.743: E/AndroidRuntime(1825): ... 12 more
而且 代碼從線423看起來是這樣的:
public boolean wczytajMape() {
if (mMap == null) {
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mMap = mapFrag.getMap();
mMap.setOnMarkerClickListener(this); \\----->423 line
mMap.setMyLocationEnabled(true);
}
return (mMap != null);
}
這種錯誤實在是煩人,它發生在10 API及API 17,這個我進行了調查。我沒有在另一個版本上測試它。任何人都可以幫助我?
檢查谷歌模擬器。您正在嘗試使用沒有MAP的普通模擬器。 –
這意味着您的mMap在該位置爲NULL。 –
是的我知道,但爲什麼在真實的設備上一切都好? – bakusek