0

我在我的 sdk 中安装了 google play 服务。我的 xml 文件附在下面

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

但是编译java文件后会引发异常。还附上了完整的日志文件。

08-05 06:02:06.686: D/AndroidRuntime(1236): Shutting down VM
08-05 06:02:06.686: W/dalvikvm(1236): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-05 06:02:06.847: E/AndroidRuntime(1236): FATAL EXCEPTION: main
08-05 06:02:06.847: E/AndroidRuntime(1236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.viewindia/com.example.viewindia.ViewIndia}: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.os.Looper.loop(Looper.java:137)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.ActivityThread.main(ActivityThread.java:5103)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at java.lang.reflect.Method.invokeNative(Native Method)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at java.lang.reflect.Method.invoke(Method.java:525)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at dalvik.system.NativeStart.main(Native Method)
08-05 06:02:06.847: E/AndroidRuntime(1236): Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Activity.setContentView(Activity.java:1895)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at com.example.viewindia.ViewIndia.onCreate(ViewIndia.java:25)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Activity.performCreate(Activity.java:5133)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-05 06:02:06.847: E/AndroidRuntime(1236):     ... 11 more
08-05 06:02:06.847: E/AndroidRuntime(1236): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Fragment.instantiate(Fragment.java:592)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Fragment.instantiate(Fragment.java:560)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Activity.onCreateView(Activity.java:4738)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
08-05 06:02:06.847: E/AndroidRuntime(1236):     ... 21 more
08-05 06:02:06.847: E/AndroidRuntime(1236): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.example.viewindia-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.viewindia-2, /system/lib]]
08-05 06:02:06.847: E/AndroidRuntime(1236):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-05 06:02:06.847: E/AndroidRuntime(1236):     at android.app.Fragment.instantiate(Fragment.java:582)
08-05 06:02:06.847: E/AndroidRuntime(1236):     ... 24 more

我怎么解决这个问题?

4

1 回答 1

1

您必须将 Google Play Service SDK 作为一个项目添加到您的工作区中(假设您使用的是 Eclipse)。这在此处进行了描述。

下一步是将此项目与您的 Android 项目作为库链接。这是有关此步骤的文档。

于 2013-08-05T10:51:43.570 回答