在很多时候都会遇到这样的问题
我在调用百度地图时就遇到了这样的问题
main.xml
<com.baidu.mapapi.map.mapView
android:id="@+id/bmapsView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" >
</com.baidu.mapapi.map.mapView>
07-10 08:33:01.585: E/AndroidRuntime(470): FATAL EXCEPTION: main
07-10 08:33:01.585: E/AndroidRuntime(470): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.baidumapsample/com.example.baidumapsample.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class com.baidu.mapapi.map.mapView
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.os.Looper.loop(Looper.java:123)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-10 08:33:01.585: E/AndroidRuntime(470): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 08:33:01.585: E/AndroidRuntime(470): at java.lang.reflect.Method.invoke(Method.java:521)
07-10 08:33:01.585: E/AndroidRuntime(470): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-10 08:33:01.585: E/AndroidRuntime(470): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-10 08:33:01.585: E/AndroidRuntime(470): at dalvik.system.NativeStart.main(Native Method)
07-10 08:33:01.585: E/AndroidRuntime(470): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.baidu.mapapi.map.mapView
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-10 08:33:01.585: E/AndroidRuntime(470): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.Activity.setContentView(Activity.java:1647)
07-10 08:33:01.585: E/AndroidRuntime(470): at com.example.baidumapsample.MainActivity.onCreate(MainActivity.java:23)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-10 08:33:01.585: E/AndroidRuntime(470): ... 11 more
07-10 08:33:01.585: E/AndroidRuntime(470): Caused by: java.lang.ClassNotFoundException: com.baidu.mapapi.map.mapView in loader dalvik.system.PathClassLoader[/data/app/com.example.baidumapsample-1.apk]
07-10 08:33:01.585: E/AndroidRuntime(470): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-10 08:33:01.585: E/AndroidRuntime(470): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-10 08:33:01.585: E/AndroidRuntime(470): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
07-10 08:33:01.585: E/AndroidRuntime(470): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
07-10 08:33:01.585: E/AndroidRuntime(470): ... 20 more
出现了以上错误
更改为:
mail.xml
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapsView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" >
</com.baidu.mapapi.map.MapView>
就可以运行了,这里有两种可能一是没事填写前面正确的包名,例如 <MapView></MapView>
另外一种就是本例类名写错了,总之,出现这个错误的原因就是没有找到对应的类
运行效果: