2013-12-12 52 views
1

我想製作一個簡單的地圖並在模擬器中進行調試。我想知道我的錯誤在哪裏,我該如何糾正它。android.view.InflateException:二進制XML文件行#1:從模擬器錯誤膨脹類片段/

這裏是:logcat的:

12-12 15:32:28.310: D/dalvikvm(879): Not late-enabling CheckJNI (already on) 
12-12 15:32:30.070: D/AndroidRuntime(879): Shutting down VM 
12-12 15:32:30.070: W/dalvikvm(879): threadid=1: thread exiting with uncaught exception (group=0xb3abdb90) 
12-12 15:32:30.150: E/AndroidRuntime(879): FATAL EXCEPTION: main 
12-12 15:32:30.150: E/AndroidRuntime(879): Process: com.exemple.mysecondapp, PID: 879 
12-12 15:32:30.150: E/AndroidRuntime(879): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exemple.mysecondapp/com.exemple.mysecondapp.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.ActivityThread.access$700(ActivityThread.java:135) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.os.Handler.dispatchMessage(Handler.java:102) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.os.Looper.loop(Looper.java:137) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.ActivityThread.main(ActivityThread.java:4998) 
12-12 15:32:30.150: E/AndroidRuntime(879): at java.lang.reflect.Method.invokeNative(Native Method) 
12-12 15:32:30.150: E/AndroidRuntime(879): at java.lang.reflect.Method.invoke(Method.java:515) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 
12-12 15:32:30.150: E/AndroidRuntime(879): at dalvik.system.NativeStart.main(Native Method) 
12-12 15:32:30.150: E/AndroidRuntime(879): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.Activity.setContentView(Activity.java:1928) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.exemple.mysecondapp.MainActivity.onCreate(MainActivity.java:21) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.Activity.performCreate(Activity.java:5243) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140) 
12-12 15:32:30.150: E/AndroidRuntime(879): ... 11 more 
12-12 15:32:30.150: E/AndroidRuntime(879): 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" /> 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.maps.internal.q.v(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.maps.internal.q.u(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.dynamic.a.a(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.dynamic.a.onInflate(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290) 
12-12 15:32:30.150: E/AndroidRuntime(879): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
12-12 15:32:30.150: E/AndroidRuntime(879): ... 20 more 
12-12 15:34:25.171: I/Process(879): Sending signal. PID: 879 SIG: 9 

主要類:

package com.exemple.mysecondapp; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 

import android.app.Dialog; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 


public class MainActivity extends FragmentActivity { 
    private GoogleMap gm; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_main); 

     int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); 

     if (status == ConnectionResult.SUCCESS) { 
      SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
     } 
     else { 
      int requestCode = 10; 
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); 
      dialog.show(); 
     } 
    } 

} 

activity_main.xml中:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment"/> 

應用程序清單:

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

<uses-sdk 
    android:minSdkVersion="12" 
    android:targetSdkVersion="19" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.exemple.mysecondapp.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> 
    <uses-library android:required="true" android:name="com.google.android.maps" /> 


    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AN API KEY"/> 
    </application>  
<meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 


<permission 
    android:name="com.exemple.mysecondapp.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"/> 
<uses-permission android:name="com.exemple.mysecondapp.permission.MAPS_RECEIVE"/> 

<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="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"/> 

我在這方面通過了很多小時,迄今沒有有效的答案。謝謝任何回答這個問題的人。

+0

見http://stackoverflow.com/questions/19723811/after-google- play-service-update-to-version-13-i-got-an-error – laalto

+0

好的,我發現了錯誤。元數據不在上述代碼中的正確位置。 – Xc43

回答

1
The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. 

您應該安裝谷歌發揮模擬器服務(基於Android 4.2.2或更高版本)

http://developer.android.com/google/play-services/setup.html

+0

我做到了。第二個元數據並不合適。現在,我獲得Google Maps Android API v2僅支持使用OpenGL ES 2.0及更高版本的設備。自從我把它放在那裏後我就不明白了。另外它應該由AVD支持。 – Xc43

相關問題