package com.home.baidumap;import com.baidu.mapapi.SDKInitializer;import com.baidu.mapapi.map.MapView;import android.app.Activity;import android.os.Bundle;import android.view.Window;public class MainActivity extends Activity { MapView mMapView=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //在使用SDK各组件之前初始化context信息,传入ApplicationContext //注意该方法要再setContentView方法之前实现 SDKInitializer.initialize(getApplicationContext()); //获取地图控件引用 mMapView = (MapView) findViewById(R.id.id_bmapView); setContentView(R.layout.activity_main); } @Override protected void onDestroy() { super.onDestroy(); //在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 mMapView.onDestroy(); } @Override protected void onResume() { super.onResume(); mMapView.onResume(); } @Override protected void onPause() { super.onPause(); //在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理 mMapView.onPause(); } }Logcat提示错处:08-22 11:22:02.320: E/AndroidRuntime(1804): FATAL EXCEPTION: mainProcess: com.home.baidumap, PID: 1804 java.lang.RuntimeException: Unable to resume activity {com.home.baidumap/com.home.baidumap.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2788) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2817) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250) at android.app.ActivityThread.access$800(ActivityThread.java:135)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) E/AndroidRuntime(1804): at dalvik.system.NativeStart.main(Native Method)Caused by: java.lang.NullPointerExceptionat com.home.baidumap.MainActivity.onResume(MainActivity.java:40) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192) at android.app.Activity.performResume(Activity.java:5310) E/AndroidRuntime at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2778)
添加回答
举报
0/150
提交
取消