Android 百度地图开发 模拟器老是不能打开,求大神指点

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: main
Process: 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.NullPointerException
at 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)


宝慕林0518688
浏览 3766回答 2
2回答

小寳_昭乂阳

楼上的回答是代码的错误,Logcat中报的错误。另外测试地图类的Demo还是用真机测试吧,模拟器不一定支持。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android
Java