更改Google地图类型时发生以下错误。
java.lang.RuntimeException:无法在android.app上启动活动ComponentInfo {com.opentruck / com.opentruck.MainActivity}:android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)中的java.lang.NullPointerException .ActivityThread.handleLaunchActivity(ActivityThread.java:2434)在Android.app.Handler的android.app.ActivityThread.access $ 800(ActivityThread.java:154)android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1347) android.app.Looper.loop(Looper.java:193)上的.dispatchMessage(Handler.java:110)位于android.app.ActivityThread.main(ActivityThread.java:5349)的java.lang.reflect.Method.invokeNative(本地方法)在com.android.internal.os的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:835)的java.lang.reflect.Method.invoke(Method.java:515)。 ZalgoteInit.main(ZygoteInit.java:651)at dalvik.system.NativeStart.main(Native Method)引起:com.opentruck.MainActivity $ 18.onCheckedChanged(MainAct)中的java.lang.NullPointerException ivity.java:890)在android.widget.TogtonButton.setChecked(ToggleButton.java:73)的android.widget.CompoundButton.setChecked(CompoundButton.java:127)android.widget.CompoundButton.onRestoreInstanceState(CompoundButton.java:381) )在android.view.View.dispatchRestoreInstanceState(View.java:12977)的android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2762)at android.view.View.restoreHierarchyState(View.java:12955)at com.android .internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1821)位于Android的android.app.Activity.performRestoreInstanceState(Activity.java:930)的android.app.Activity.onRestoreInstanceState(Activity.java:958)。 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2350)上的app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1140)... com.opentruck.MainActivity $ 11.onCheckedChanged(MainActivity.java)中的另外11个java.lang.NullPointerException :890)在android.widget.CompoundButton.setChecked(Compou ndButton.java:127)在android.widget.ToggleButton.setChecked(ToggleButton.java:73)的android.widget.CompoundButton.onRestoreInstanceState(CompoundButton.java:381)
以下是更改谷歌地图视图类型的代码。
toggleMapType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (Utils.isAvailablePlayService(MainActivity.this)) {
if (isChecked) {
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
} else {
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
}
}
);