如何在Android 4.0中集成Google maps v2?

时间:2013-11-07 19:11:05

标签: java android android-maps-v2

这是我的问题:

我一直在做这个教程: http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ (还有更多,但每一个都给我错误)

我已经完成了所需的一切(权限,库,API代码)。 API代码正确完成!

以下是一些截图: - activity_main.xml [1] http://i.imgur.com/MwLwMtu.jpg

错误:

11-07 20:02:28.969: E/Godfrey5(5234): BitmapFactory.java, decodeStream()
11-07 20:02:28.969: E/BitmapFactory(5234): Godfrey5==BitmapFactory.cpp, nativeDecodeAsset()
11-07 20:02:28.969: E/BitmapFactory(5234): Godfrey5==BitmapFactory.cpp, doDecode()
11-07 20:02:28.969: E/BitmapFactory(5234): Godfrey5==BitmapFactory.cpp, doDecode(),filename=(null)
11-07 20:02:29.019: E/Godfrey5(5234): BitmapFactory.java, decodeStream()
11-07 20:02:29.019: E/BitmapFactory(5234): Godfrey5==BitmapFactory.cpp, nativeDecodeAsset()
11-07 20:02:29.019: E/BitmapFactory(5234): Godfrey5==BitmapFactory.cpp, doDecode()
11-07 20:02:29.019: E/BitmapFactory(5234): Godfrey5==BitmapFactory.cpp, doDecode(),filename=(null)
11-07 20:02:29.049: W/dalvikvm(5234): threadid=1: thread exiting with uncaught exception (group=0x416d1438)
11-07 20:02:29.079: E/AndroidRuntime(5234): FATAL EXCEPTION: main
11-07 20:02:29.079: E/AndroidRuntime(5234): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.money.irl/com.money.irl.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2062)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.ActivityThread.access$600(ActivityThread.java:133)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.os.Looper.loop(Looper.java:137)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.ActivityThread.main(ActivityThread.java:4777)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at java.lang.reflect.Method.invokeNative(Native Method)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at java.lang.reflect.Method.invoke(Method.java:511)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at dalvik.system.NativeStart.main(Native Method)
11-07 20:02:29.079: E/AndroidRuntime(5234): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.Activity.setContentView(Activity.java:1867)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.money.irl.MainActivity.onCreate(MainActivity.java:15)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.Activity.performCreate(Activity.java:5008)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2026)
11-07 20:02:29.079: E/AndroidRuntime(5234):     ... 11 more
11-07 20:02:29.079: E/AndroidRuntime(5234): 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-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.dynamic.a.a(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.app.Activity.onCreateView(Activity.java:4663)
11-07 20:02:29.079: E/AndroidRuntime(5234):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-07 20:02:29.079: E/AndroidRuntime(5234):     ... 21 more

该项目使用Google API编译,加载了库(google-play-services_lib),MainActivity.java中没有添加任何代码(仅从Eclipse生成)。

我通过右键单击项目添加了支持库&gt; Android工具&gt;添加支持库,接受并安装。

当我尝试启动手机(中兴刀片3专业版)时,应用程序出错。如果我删除&#34;

1 个答案:

答案 0 :(得分:0)

@tyczj在这里和其他许多人的回答:

只需在AndroidManifest.xml中添加以上内容,而无需更改此代码中的任何内容:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />*