0

我得到de錯誤,當我嘗試運行我的應用程序。我試圖用導入將類改爲extends Fragmentextends FragmentActivity,但沒有奏效。 因爲我已經在我的Manifest中添加了一些額外的信息,我想你可能有些事情可能會導致報告的問題。錯誤InflateException Android 6.0

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="luizugliano.com.br.googlemapsapp" > 

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

<!--Mostrar a localização atual--> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

<!-- Required OpenGL ES 2.0. for Maps V2 --> 
<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<!-- Requires OpenGL ES version 2 --> 
<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    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="AIzaSyAjLBXa8xptO-7CRhvhRQMX8zB-85uR7LU"/> 

    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

logcat的錯誤

FATAL EXCEPTION: main 
11-17 22:55:13.475 3005-3005/luizugliano.com.br.googlemapsapp E/AndroidRuntime: Process: luizugliano.com.br.googlemapsapp, PID: 3005 
11-17 22:55:13.475 3005-3005/luizugliano.com.br.googlemapsapp E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{luizugliano.com.br.googlemapsapp/luizugliano.com.br.googlemapsapp.Ma inActivity}: android.view.InflateException: Binary XML file line #18: Binary XML file line #12: Error inflating class fragment 
11-17 22:55:13.475 3005-3005/luizugliano.com.br.googlemapsapp E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
11-17 22:55:13.475 3005-3005/luizugliano.com.br.googlemapsapp E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 

我content_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:showIn="@layout/activity_main" 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" 
    android:name="com.google.android.gms.maps.MapFragment"/> 

</RelativeLayout> 

我的MainActivity

​​
+0

請將您的清單文件 –

+0

@JDev,OK,完成! –

+0

你試過這個嗎? http://stackoverflow.com/a/19952291/3118054 –

回答

2

我想你應該爲你正在使用的SupportLibraries AppCompatActivity使用android:name="com.google.android.gms.maps.SupportMapFragment",而不是android:name="com.google.android.gms.maps.MapFragment"

我想你也應該用getSupportFragmentManager()替換getFragmentManager()出於同樣的原因。

在支持庫和常規API中有相同的類有時是屁股真正的痛苦,因爲你總是要確保你使用正確的。

+0

除了您提到的更改,我還必須將'MapFragment'更改爲'SupportMapFragment',但仍然返回相同的錯誤。更改後的代碼:'googleMap =((SupportMapFragment)getSupportFragmentManager()。findFragmentById( R.id.map))。getMap();'。 –

+0

我想你正在使用android studio。你在build.gradle中包含了'google-play-services'的依賴關係嗎? –

+0

是的 - 我包括'編譯'com.google.android.gms:play-services:4.2。+'' –

相關問題