0
我知道有一堆關於這個帖子,但我不能讓我的谷歌地圖工作。我曾嘗試百萬個不同的方式來獲得這一點,我發現,最好的辦法是這樣的:另一個谷歌地圖V2無法膨脹請問
MainActivity.java
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml中
<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"
tools:context=".MainActivity" >
<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"
android:name="in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity"/>
</RelativeLayout>
的Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.wptrafficanalyzer.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
<permission
android:name="in.wptrafficanalyzer.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="in.wptrafficanalyzer.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAxS05MA_zbMWq27N83FOqKh7MlwLz-2Lg"/>
</application>
</manifest>
但我仍然得到這個錯誤,很多人都得到:( 而我實現了谷歌,播放services_lib
05-13 13:18:39.673: E/ActivityThread(14542): Failed to inflate
05-13 13:18:39.673: E/ActivityThread(14542): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-13 13:18:39.673: E/ActivityThread(14542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-13 13:18:39.673: E/ActivityThread(14542): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-13 13:18:39.673: E/ActivityThread(14542): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-13 13:18:39.673: E/ActivityThread(14542): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-13 13:18:39.673: E/ActivityThread(14542): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-13 13:18:39.673: E/ActivityThread(14542): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.Activity.setContentView(Activity.java:1881)
05-13 13:18:39.673: E/ActivityThread(14542): at in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity.onCreate(MainActivity.java:12)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.Activity.performCreate(Activity.java:5122)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2432)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2530)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.ActivityThread.access$600(ActivityThread.java:176)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1385)
05-13 13:18:39.673: E/ActivityThread(14542): at android.os.Handler.dispatchMessage(Handler.java:107)
05-13 13:18:39.673: E/ActivityThread(14542): at android.os.Looper.loop(Looper.java:194)
05-13 13:18:39.673: E/ActivityThread(14542): at android.app.ActivityThread.main(ActivityThread.java:5546)
05-13 13:18:39.673: E/ActivityThread(14542): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 13:18:39.673: E/ActivityThread(14542): at java.lang.reflect.Method.invoke(Method.java:525)
05-13 13:18:39.673: E/ActivityThread(14542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-13 13:18:39.673: E/ActivityThread(14542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
05-13 13:18:39.673: E/ActivityThread(14542): at dalvik.system.NativeStart.main(Native Method)
05-13 13:18:39.673: E/ActivityThread(14542): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 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" />
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.maps.internal.q.B(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.maps.internal.q.A(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.dynamic.a.a(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-13 13:18:39.673: E/ActivityThread(14542): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
05-13 13:18:39.673: E/ActivityThread(14542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-13 13:18:39.673: E/ActivityThread(14542): ... 21 more
05-13 13:18:39.683: E/AndroidRuntime(14542): FATAL EXCEPTION: main
05-13 13:18:39.683: E/AndroidRuntime(14542): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2478)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2530)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.ActivityThread.access$600(ActivityThread.java:176)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1385)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.os.Handler.dispatchMessage(Handler.java:107)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.os.Looper.loop(Looper.java:194)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.ActivityThread.main(ActivityThread.java:5546)
05-13 13:18:39.683: E/AndroidRuntime(14542): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 13:18:39.683: E/AndroidRuntime(14542): at java.lang.reflect.Method.invoke(Method.java:525)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
05-13 13:18:39.683: E/AndroidRuntime(14542): at dalvik.system.NativeStart.main(Native Method)
05-13 13:18:39.683: E/AndroidRuntime(14542): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.Activity.setContentView(Activity.java:1881)
05-13 13:18:39.683: E/AndroidRuntime(14542): at in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity.onCreate(MainActivity.java:12)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.Activity.performCreate(Activity.java:5122)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2432)
05-13 13:18:39.683: E/AndroidRuntime(14542): ... 11 more
05-13 13:18:39.683: E/AndroidRuntime(14542): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 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" />
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.maps.internal.q.B(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.maps.internal.q.A(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.dynamic.a.a(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
05-13 13:18:39.683: E/AndroidRuntime(14542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-13 13:18:39.683: E/AndroidRuntime(14542): ... 21 more
請人能幫助我的人......我試圖做簡單的谷歌地圖應用的一個多月,我跑出來的選項...: (
-1不要發佈[重複答案](http://stackoverflow.com/a/22112669/474189)。投票關閉作爲一個副本,而不是。 –
@Duncan抱歉budy我的錯誤! –
我很抱歉重複,但這個錯誤仍然沒有解決... @鄧肯,謝謝你的回答,但它仍然給我相同的inflater錯誤... – user3632055