java.lang.RuntimeException:无法启动活动ComponentInfo android.view.InflateException:二进制XML文件行#11:

时间:2015-09-07 06:51:10

标签: android google-maps inflate-exception

嗨,我想将谷歌地图添加到我的项目,但我有错误,我不解决

logcat的:

09-07 06:19:26.849: E/AndroidRuntime(908): FATAL EXCEPTION: main
09-07 06:19:26.849: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.learn2develop.LBS/net.learn2develop.LBS.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.os.Looper.loop(Looper.java:137)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.ActivityThread.main(ActivityThread.java:5039)
09-07 06:19:26.849: E/AndroidRuntime(908):  at java.lang.reflect.Method.invokeNative(Native Method)
09-07 06:19:26.849: E/AndroidRuntime(908):  at java.lang.reflect.Method.invoke(Method.java:511)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-07 06:19:26.849: E/AndroidRuntime(908):  at dalvik.system.NativeStart.main(Native Method)
09-07 06:19:26.849: E/AndroidRuntime(908): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.Activity.setContentView(Activity.java:1881)
09-07 06:19:26.849: E/AndroidRuntime(908):  at net.learn2develop.LBS.MainActivity.onCreate(MainActivity.java:18)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.Activity.performCreate(Activity.java:5104)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-07 06:19:26.849: E/AndroidRuntime(908):  ... 11 more
09-07 06:19:26.849: E/AndroidRuntime(908): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 7095000 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" />
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.common.GooglePlayServicesUtil.zzJ(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.maps.internal.zzx.zzad(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.maps.internal.zzx.zzac(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.maps.MapFragment$zzb.zzqs(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.dynamic.zza.zza(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.app.Activity.onCreateView(Activity.java:4716)
09-07 06:19:26.849: E/AndroidRuntime(908):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-07 06:19:26.849: E/AndroidRuntime(908):  ... 21 more

MainActivity.java

    package net.learn2develop.LBS;

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

    public class MainActivity extends Activity {   

    private GoogleMap mMap;         
    @Override     
        protected void onCreate(Bundle savedInstanceState) {         
            super.onCreate(savedInstanceState);         
            setContentView(R.layout.main);             
            mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();         
            mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);         
            final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);         
            Marker ciu = mMap.addMarker(new MarkerOptions()                                   
            .position(CIU).title("My Office"));     
        }     
    @Override     
        public boolean onCreateOptionsMenu(Menu menu) {         
        // Inflate the menu; this adds items to the action bar if it is present.         
        getMenuInflater().inflate(R.menu.main, menu);         
        return true;     
        }
    } 

main.xml中

&#13;
&#13;
	 <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" >
	<TextView        
	android:layout_width="wrap_content"        
	android:layout_height="wrap_content"        
	android:text="hello_world" />
	<fragment
	        android:id="@+id/map"     
	        android:layout_width="match_parent"        
	        android:layout_height="match_parent"        
	class="com.google.android.gms.maps.MapFragment"/>
	</RelativeLayout>
&#13;
&#13;
&#13;

的manifest.xml

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.learn2develop.LBS"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
        <permission
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"></permission>
    <uses-permission
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
    <uses-permission
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission
        android:name="android.permission.INTERNET"/>
    <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" >
          <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/>
        <activity
            android:name="net.learn2develop.LBS.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>

</manifest>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

异常日志明确指出要在清单

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

有关设置Google Play服务API的信息,请阅读

https://developers.google.com/android/guides/setup

答案 1 :(得分:-1)

Exception明确表示Android清单缺少元标记

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

XML文件行no-11 中,检查片段&amp;谷歌播放服务jar文件。添加适当的依赖项。