2015-07-05 72 views
1

我想craete谷歌地圖項目。我已經導入了google-play-service庫並啓用了Google Maps Android API 2以及創建的android API密鑰。編輯我的manifest.xml後,我收到以下錯誤:引起:android.view.InflateException:二進制XML文件行#1:錯誤膨脹類片段

錯誤

07-05 10:21:43.525: E/AndroidRuntime(13988): FATAL EXCEPTION: main 
07-05 10:21:43.525: E/AndroidRuntime(13988): Process: com.example.map, PID: 13988 
07-05 10:21:43.525: E/AndroidRuntime(13988): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.ActivityThread.access$900(ActivityThread.java:177) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.os.Handler.dispatchMessage(Handler.java:102) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.os.Looper.loop(Looper.java:145) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.ActivityThread.main(ActivityThread.java:5944) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at java.lang.reflect.Method.invoke(Native Method) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at java.lang.reflect.Method.invoke(Method.java:372) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184) 
07-05 10:21:43.525: E/AndroidRuntime(13988): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.example.map.MainActivity.onCreate(MainActivity.java:14) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.Activity.performCreate(Activity.java:6289) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) 
07-05 10:21:43.525: E/AndroidRuntime(13988): ... 10 more 
07-05 10:21:43.525: E/AndroidRuntime(13988): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.maps.api.android.lib6.d.fk.a(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.maps.api.android.lib6.a.g.a(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.internal.i.onTransact(SourceFile:62) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.os.Binder.transact(Binder.java:380) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.internal.zzc$zza$zza.zzr(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.SupportMapFragment$zzb.zzvu(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.dynamic.zza.zza(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.dynamic.zza.onInflate(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2169) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:838) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:826) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) 
07-05 10:21:43.525: E/AndroidRuntime(13988): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732) 
07-05 10:21:43.525: E/AndroidRuntime(13988): ... 19 more 

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.map" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="21" /> 
    <uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

<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=".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.gms.version" 
    android:value="TIzaSyDS5wem-JxFUXnw8uVNljCNlm4NRwGAZQs" /> 

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

    </application> 

</manifest> 

activity_main.xml中

<fragment 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" 
    android:id="@+id/map" 
    tools:context=".MapsActivity" 
    android:name="com.google.android.gms.maps.SupportMapFragment" /> 

** MainActivity:**

package com.example.map; 

import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 


public class MainActivity extends ActionBarActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 
+0

'產生的原因:了java.lang.RuntimeException:API密鑰未找到。檢查位於AndroidManifest.xml的元素中# –

回答

3

你忘了你的地圖API密鑰添加到您的manifest.xml

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

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

     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="TIzaSyDS5wem-JxFUXnw8uVNljCNlm4NRwGAZQs" /> 

     <activity 
      android:name=".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> 
</application> 
+0

此值爲TIzaSyDS5wem-JxFUXnw8uVNljCNlm4NRwGAZQs '是我的鑰匙。那麼我必須用'「YOUR_MAP_API_KEY」替換它'' –

+0

@light,確實如此。我會編輯我的答案,然後:) – blueware

相關問題