这是我第一次开发 Android 应用程序,我的第一个目标是让一个简单的地图控件出现在屏幕上。代码和一切看起来都不错,除了应用程序在我的 2.3.7 手机上运行时崩溃!我正在使用 Google API v2 页面中的示例,但它仍然无法正常工作。
我的 Android 手机运行的是 2.3.7 Android 版本。
编码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MapActivity" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
怎么了?
08-15 00:06:46.230: E/ActivityThread(11383): Failed to inflate
08-15 00:06:46.230: E/ActivityThread(11383): android.view.InflateException: Binary XML file line #11: Error inflating class fragment
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-15 00:06:46.230: E/ActivityThread(11383): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.Activity.setContentView(Activity.java:1657)
08-15 00:06:46.230: E/ActivityThread(11383): at com.cefetmgrdctcc.sgtp.MapActivity.onCreate(MapActivity.java:13)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
08-15 00:06:46.230: E/ActivityThread(11383): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 00:06:46.230: E/ActivityThread(11383): at android.os.Looper.loop(Looper.java:130)
08-15 00:06:46.230: E/ActivityThread(11383): at android.app.ActivityThread.main(ActivityThread.java:3835)
08-15 00:06:46.230: E/ActivityThread(11383): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 00:06:46.230: E/ActivityThread(11383): at java.lang.reflect.Method.invoke(Method.java:507)
08-15 00:06:46.230: E/ActivityThread(11383): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
08-15 00:06:46.230: E/ActivityThread(11383): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
08-15 00:06:46.230: E/ActivityThread(11383): at dalvik.system.NativeStart.main(Native Method)
08-15 00:06:46.230: E/ActivityThread(11383): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.cefetmgrdctcc.sgtp-2.apk]
08-15 00:06:46.230: E/ActivityThread(11383): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-15 00:06:46.230: E/ActivityThread(11383): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-15 00:06:46.230: E/ActivityThread(11383): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
08-15 00:06:46.230: E/ActivityThread(11383): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
08-15 00:06:46.230: E/ActivityThread(11383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-15 00:06:46.230: E/ActivityThread(11383): ... 20 more
08-15 00:06:46.238: D/AndroidRuntime(11383): Shutting down VM
08-15 00:06:46.238: W/dalvikvm(11383): threadid=1: thread exiting with uncaught exception (group=0x40018560)
08-15 00:06:46.246: E/AndroidRuntime(11383): FATAL EXCEPTION: main
08-15 00:06:46.246: E/AndroidRuntime(11383): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cefetmgrdctcc.sgtp/com.cefetmgrdctcc.sgtp.MapActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.os.Looper.loop(Looper.java:130)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.ActivityThread.main(ActivityThread.java:3835)
08-15 00:06:46.246: E/AndroidRuntime(11383): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 00:06:46.246: E/AndroidRuntime(11383): at java.lang.reflect.Method.invoke(Method.java:507)
08-15 00:06:46.246: E/AndroidRuntime(11383): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
08-15 00:06:46.246: E/AndroidRuntime(11383): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
08-15 00:06:46.246: E/AndroidRuntime(11383): at dalvik.system.NativeStart.main(Native Method)
08-15 00:06:46.246: E/AndroidRuntime(11383): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-15 00:06:46.246: E/AndroidRuntime(11383): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.Activity.setContentView(Activity.java:1657)
08-15 00:06:46.246: E/AndroidRuntime(11383): at com.cefetmgrdctcc.sgtp.MapActivity.onCreate(MapActivity.java:13)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
08-15 00:06:46.246: E/AndroidRuntime(11383): ... 11 more
08-15 00:06:46.246: E/AndroidRuntime(11383): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.cefetmgrdctcc.sgtp-2.apk]
08-15 00:06:46.246: E/AndroidRuntime(11383): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-15 00:06:46.246: E/AndroidRuntime(11383): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-15 00:06:46.246: E/AndroidRuntime(11383): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
08-15 00:06:46.246: E/AndroidRuntime(11383): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
08-15 00:06:46.246: E/AndroidRuntime(11383): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-15 00:06:46.246: E/AndroidRuntime(11383): ... 20 more
感谢您的阅读!