3
我創建一個MapView
程序是這樣的:MapView類的NullPointerException在的onCreate
MapView mv = new MapView(this);
然而,這導致了NullPointerException
(查看日誌)。如果我使用另一個構造函數,如
MapView mv = new MapView(this, new GoogleMapOptions());
一切都很好。有什麼事?
的onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listings);
mSmallMapView = new MapView(this);
mSmallMapView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 200));
this.addView(mSmallMapView);
mSmallMapView.onCreate(savedInstanceState);
}
logcat的:
01-19 01:28:20.411: E/AndroidRuntime(16039): FATAL EXCEPTION: main
01-19 01:28:20.411: E/AndroidRuntime(16039): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.ui.ListingsActivity}: java.lang.NullPointerException
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.os.Looper.loop(Looper.java:137)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-19 01:28:20.411: E/AndroidRuntime(16039): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 01:28:20.411: E/AndroidRuntime(16039): at java.lang.reflect.Method.invoke(Method.java:511)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-19 01:28:20.411: E/AndroidRuntime(16039): at dalvik.system.NativeStart.main(Native Method)
01-19 01:28:20.411: E/AndroidRuntime(16039): Caused by: java.lang.NullPointerException
01-19 01:28:20.411: E/AndroidRuntime(16039): at maps.am.r.a(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at maps.y.ae.a(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at maps.y.bm.onCreate(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.maps.internal.IMapViewDelegate$Stub.onTransact(IMapViewDelegate.java:66)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.os.Binder.transact(Binder.java:310)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.maps.internal.IMapViewDelegate$a$a.onCreate(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.maps.MapView$b.onCreate(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.internal.d$3.a(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.internal.i.b(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.maps.MapView$a.a(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.maps.MapView$a.a(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.internal.d.a(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.internal.d.onCreate(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.google.android.gms.maps.MapView.onCreate(Unknown Source)
01-19 01:28:20.411: E/AndroidRuntime(16039): at com.example.ui.ListingsActivity.onCreate(ListingsActivity.java:108)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.Activity.performCreate(Activity.java:5104)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-19 01:28:20.411: E/AndroidRuntime(16039): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-19 01:28:20.411: E/AndroidRuntime(16039): ... 11 more
把你的oncreate方法放在這裏 –
你的活動擴展了'MapActivity'嗎? – tolgap
哦,我應該說我正在使用'Google Maps Android API v2',我認爲沒有像'MapActivity'這樣的東西......還有,正如我所提到的,使用其他構造函數,一切都很完美。我只是想知道這是否是我的錯,這是一個錯誤。 – Max