更新:
在我的Android SDK Manager中,我安装了Android支持库。在我的Downloads / android-sdk-macosx / extras / android / support目录中,我有一个v4,一个v7和v13。我将android-support-v4.jar复制到了libs文件夹。右键单击并选择Build Path>配置构建路径。在活动布局中,我添加了以下内容(使用supportmapfragment而不是mapfragment):
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
但我仍然得到这个错误:
04-16 17:42:00.928: E/AndroidRuntime(363): FATAL EXCEPTION: main
04-16 17:42:00.928: E/AndroidRuntime(363):
java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.otl.AndroidRemoteApp1/
com.otl.AndroidRemoteApp.ShowMapActivity}:
android.view.InflateException: Binary XML file line #6: Error
inflating class fragment
以下是完整的跟踪:
04-18 10:33:32.075: E/AndroidRuntime(368): FATAL EXCEPTION: main
04-18 10:33:32.075: E/AndroidRuntime(368): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.otl.AndroidRemoteApp1/com.otl.AndroidRemoteApp.ShowMapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.os.Looper.loop(Looper.java:130)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-18 10:33:32.075: E/AndroidRuntime(368): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 10:33:32.075: E/AndroidRuntime(368): at java.lang.reflect.Method.invoke(Method.java:507)
04-18 10:33:32.075: E/AndroidRuntime(368): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-18 10:33:32.075: E/AndroidRuntime(368): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-18 10:33:32.075: E/AndroidRuntime(368): at dalvik.system.NativeStart.main(Native Method)
04-18 10:33:32.075: E/AndroidRuntime(368): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-18 10:33:32.075: E/AndroidRuntime(368): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.Activity.setContentView(Activity.java:1657)
04-18 10:33:32.075: E/AndroidRuntime(368): at com.otl.AndroidRemoteApp.ShowMapActivity.onCreate(ShowMapActivity.java:45)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-18 10:33:32.075: E/AndroidRuntime(368): ... 11 more
04-18 10:33:32.075: E/AndroidRuntime(368): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.otl.AndroidRemoteApp1-2.apk]
04-18 10:33:32.075: E/AndroidRuntime(368): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-18 10:33:32.075: E/AndroidRuntime(368): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-18 10:33:32.075: E/AndroidRuntime(368): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
04-18 10:33:32.075: E/AndroidRuntime(368): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-18 10:33:32.075: E/AndroidRuntime(368): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-18 10:33:32.075: E/AndroidRuntime(368): ... 20 more
有什么想法吗?
答案 0 :(得分:2)
仅在API级别12之后才支持MapFragment。建议改为使用SupportMapFragment。
要使用此功能,您需要在您的路径中包含Android支持库。按照这些instructions将支持库添加到项目中。
更新:
此外,在API级别11之前,Fragment类不可用。我相信您的目标是使用API级别为10的Gingerbread。这就是您收到以下错误的原因:
Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader
请参阅此Question,它看起来是一个类似的问题。