使用百度地图SDK,运行Demo还可以的,但是当用到自己的程序中就出现问题了:
报出异常如下:
- 07-27 10:31:59.501: E/AndroidRuntime(8282): FATAL EXCEPTION: main
- 07-27 10:31:59.501: E/AndroidRuntime(8282): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Casper.UI/com.Casper.subUI.Trans_Location}: android.view.InflateException: Binary XML file line #6: Error inflating class com.baidu.mapapi.map.MapView
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.ActivityThread.access$600(ActivityThread.java:156)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.os.Handler.dispatchMessage(Handler.java:99)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.os.Looper.loop(Looper.java:153)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.ActivityThread.main(ActivityThread.java:5297)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at java.lang.reflect.Method.invokeNative(Native Method)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at java.lang.reflect.Method.invoke(Method.java:511)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at dalvik.system.NativeStart.main(Native Method)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.baidu.mapapi.map.MapView
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.Activity.setContentView(Activity.java:1881)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.Casper.subUI.Trans_Location.onCreate(Trans_Location.java:51)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.Activity.performCreate(Activity.java:5122)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): ... 11 more
- 07-27 10:31:59.501: E/AndroidRuntime(8282): Caused by: java.lang.reflect.InvocationTargetException
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at java.lang.reflect.Constructor.constructNative(Native Method)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): ... 22 more
- 07-27 10:31:59.501: E/AndroidRuntime(8282): Caused by: java.lang.IllegalStateException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.baidu.mapapi.a.b(Unknown Source)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.baidu.mapapi.map.MapView.a(Unknown Source)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): at com.baidu.mapapi.map.MapView.<init>(Unknown Source)
- 07-27 10:31:59.501: E/AndroidRuntime(8282): ... 25 more
在网上查了一天的,没办法解决。
网上出现这样错误的原因有很多:
一、没有把百度的.jar包导进来,因为使用的百度地图是第三方的,需要把它写到一个自己创建的libs文件夹下,还有把里面的.os文件也放到下面。
二、在继承FragmentActivity的要使用android.support.v4.app.FragmentActivity;而不是使用android.app.FragmentActivity.
三、因为没有编译成功的原理,有时候需要将工程clean一下
四、没有将申请百度地图key放到Manifest.xml文件中,那样根本不可能使用的。
但是我的错误都不是上面的问题,在百度地图Demo中有一个Application的类,那是一个配置整个application的类,使用的时候一定要定义这个类,同时还要把这个类放到Manifest.xml文件中说明一下:
- <application
- android:name="com.Casper.ApplicationConfig.ApplicationConfig"
- android:debuggable="true"
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
android:theme="@style/AppTheme" >
遇到了和这个同样的问题 就把这个转载过来了:http://blog.csdn.net/u010428517/article/details/38168219?reload