我在 stackoverflow 中发现了类似的主题,但对我没有帮助。我想显示地图,但是当我运行它时,它会返回强制关闭。以下是代码:
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
这是我的布局:
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_margin="20dp"
class="com.google.android.gms.maps.MapFragment" />
这是我的清单:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_API_KEY" />
</application>
这是我的日志:
11-13 16:03:10.652: E/AndroidRuntime(32202): FATAL EXCEPTION: main
11-13 16:03:10.652: E/AndroidRuntime(32202): java.lang.RuntimeException: Unable to start activity ComponentInfo{id.go.kpp.aplikasipupi/id.go.kpp.aplikasipupi.kartu}: android.view.InflateException: Binary XML file line #739: Error inflating class fragment
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.ActivityThread.access$600(ActivityThread.java:140)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.os.Looper.loop(Looper.java:137)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.ActivityThread.main(ActivityThread.java:4895)
11-13 16:03:10.652: E/AndroidRuntime(32202): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 16:03:10.652: E/AndroidRuntime(32202): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
11-13 16:03:10.652: E/AndroidRuntime(32202): at dalvik.system.NativeStart.main(Native Method)
11-13 16:03:10.652: E/AndroidRuntime(32202): Caused by: android.view.InflateException: Binary XML file line #739: Error inflating class fragment
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.Activity.setContentView(Activity.java:1912)
11-13 16:03:10.652: E/AndroidRuntime(32202): at id.go.kpp.aplikasipupi.kartu.onCreate(kartu.java:100)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.Activity.performCreate(Activity.java:5163)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
11-13 16:03:10.652: E/AndroidRuntime(32202): ... 11 more
11-13 16:03:10.652: E/AndroidRuntime(32202): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.dynamic.a.a(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.app.Activity.onCreateView(Activity.java:4813)
11-13 16:03:10.652: E/AndroidRuntime(32202): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-13 16:03:10.652: E/AndroidRuntime(32202): ... 24 more
我不知道为什么它仍然错误,我希望有人可以帮助我解决我的问题。