使用百度 com.baidu.mapapi.map.MapView创建对象时出错

今天突然出现了一个错误,也是因为我使用模拟器之后的错误,百度地图在使用模拟器初始化会出错,百度他本身不支持google的模拟器,所以我就把 SDKInitializer.initialize(getApplicationContext());给注释了,然后就出现下面的问题了

初始化百度自定义的 MapView出现发下错误

mMapView = new MapView(mActivity)

  • java.lang.ExceptionInInitializerError
  • Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘java.io.File android.content.Context.getFilesDir()’ on a null object reference
  • com.baidu.mapapi.map.MapView.(Unknown Source:17)

出现的这些错误都是和百度核心有关,他只是重写 ViewGroup 可他里面引用了很多其他mapsdk函数。所以要解决这些问题就可以出现下面的解决方法了

  • 查看 百度初始化成功了吗?(SDKInitializer.initialize(getApplicationContext());)
  • 查看 so包有添加相对应的包了吗?(so包要和jar包对应版本)
  • 查看 gradle有引用so包配置吗? ( jniLibs.srcDirs = [‘src/main/libs’] 或者
    jniLibs.srcDir [‘libs’] )
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ytf.childrenwatch, PID: 32627
    java.lang.ExceptionInInitializerError
        at com.baidu.mapsdkplatform.comapi.a.a(Unknown Source:0)
        at com.baidu.mapapi.BMapManager.getContext(Unknown Source:0)
        at com.baidu.mapsdkplatform.comapi.map.i.(Unknown Source:0)
        at com.baidu.mapsdkplatform.comapi.map.i.a(Unknown Source:0)
        at com.baidu.mapapi.map.MapView.a(Unknown Source:2)
        at com.baidu.mapapi.map.MapView.(Unknown Source:17)
        at com.ytf.childrenwatch.ui.fragment.LocationFragment.initBaiDuMap(LocationFragment.java:261)
        at com.ytf.childrenwatch.ui.fragment.LocationFragment.onFirstUserVisible(LocationFragment.java:253)
        at com.ytf.childrenwatch.ui.fragment.BaseFragment.onActivityCreated(BaseFragment.java:61)
        at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2460)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1340)
        at android.app.Activity.performStart(Activity.java:7200)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2920)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6942)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference
        at com.baidu.mapsdkplatform.comapi.NativeLoader.b(Unknown Source:4)
        at com.baidu.mapsdkplatform.comapi.NativeLoader.a(Unknown Source:4)
        at com.baidu.mapsdkplatform.comapi.NativeLoader.c(Unknown Source:2)
        at com.baidu.mapsdkplatform.comapi.NativeLoader.b(Unknown Source:65)
        at com.baidu.mapsdkplatform.comapi.NativeLoader.a(Unknown Source:35)
        at com.baidu.mapsdkplatform.comapi.NativeLoader.loadLibrary(Unknown Source:5)
        at com.baidu.mapsdkplatform.comapi.a.(Unknown Source:20)
        at com.baidu.mapsdkplatform.comapi.a.a(Unknown Source:0) 
        at com.baidu.mapapi.BMapManager.getContext(Unknown Source:0) 
        at com.baidu.mapsdkplatform.comapi.map.i.(Unknown Source:0) 
        at com.baidu.mapsdkplatform.comapi.map.i.a(Unknown Source:0) 
        at com.baidu.mapapi.map.MapView.a(Unknown Source:2) 
        at com.baidu.mapapi.map.MapView.(Unknown Source:17) 
        at com.ytf.childrenwatch.ui.fragment.LocationFragment.initBaiDuMap(LocationFragment.java:261) 
        at com.ytf.childrenwatch.ui.fragment.LocationFragment.onFirstUserVisible(LocationFragment.java:253) 
        at com.ytf.childrenwatch.ui.fragment.BaseFragment.onActivityCreated(BaseFragment.java:61) 
        at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2460) 
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483) 
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) 
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) 
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802) 
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) 
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) 
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) 
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) 
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273) 
        at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) 
        at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) 
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620) 
        at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178) 
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1340) 
        at android.app.Activity.performStart(Activity.java:7200) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2920) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6942) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

你可能感兴趣的:(Android)