36

私は自分の手と Android アプリケーション開発を試みています。私は現在Eclipseを使用しています(最新のものであっても、バージョンを思い出せません)。何が間違っているのか理解できない橋を渡ってしまいました。Google Maps V2 API を使用しようとしています。私はいくつかのドキュメントを調べ、いくつかの手法を試しましたが、そのすべてが同じエラーにつながりました:

Android.view.Inflate Exception: Binary XML file line #2: Error inflating class fragment

ここで何が間違っているのかを把握しようとして、2日間連続してキーに顔を叩きつけてきました。

私がやったこと:

  1. 真っ白な活動からスタート。
  2. Project -> Properties -> Android -> Project Build Target is Google APIs - 4.2 - API 17 - 他のすべてのオプションも試しました (バージョン 3.0 を超える限り、文書化されていることがわかりました)
  3. Package Explorer に google-play-services_lib を追加しました。google-play-services_lib が確かにa library.
  4. Project -> Properties -> Android -> Library -> Add -> google-play-services_lib の場所を選択します。
  5. android-support-v4.jar私のプロジェクトの依存関係として含まれています。

私は私のものに似た質問から非常に多くの異なる答えを試しましたが、役に立ちませんでした。:( 通常はこれらのことを理解できますが、過負荷になっている可能性があります。

日食の私のパッケージエクスプローラーツリーは次のようになります

  1. google-play-services_lib
  2. スマ

コードは次のとおりです:>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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"/>

マニフェスト

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

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

    <permission
        android:name="com.testing.svma.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.testing.svma.permission.MAPS_RECEIVE" />
    <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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.testing.svma.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="SHA1_Generated_KEY_HERE" />
    </application>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
</manifest>

MainActivity.java

package com.testing.svma;

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

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }
}

参考文献

  1. 問題を解決するために、Google マップで「Error inflating class fragment」を使用しました。

  2. この Google マップのクイック スタート ガイドを参照して、プロジェクトを作成しました。

  3. 最初は、Google Maps Android V2 Api の紹介のサンプル コードから始めました。

  4. SOの質問がたくさんあります。

だから、SOコミュニティ、私は何が間違っているのですか? なぜ私はこの単純な概念を理解できないのですか?

前もって感謝します。

4

16 に答える 16

23

同じコード/同じ問題があります! android:name="com.testing.svma.MainActivity" をレイアウトの "fragment" に追加してみてください! それは私のために問題を解決しました

<?xml version="1.0" encoding="utf-8"?>
<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="com.testing.svma.MainActivity"/>
于 2013-02-21T15:06:50.377 に答える
6

私は同じ問題を抱えていましたが、マニフェストを変更することで解決しました。これが私のマニフェストです。

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

        <permission 
               android:name="example.gps.permission.MAPS_RECEIVE" 
               android:protectionLevel="signature"></permission>
      <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
         <uses-sdk
           android:minSdkVersion="9"
           android:targetSdkVersion="17"/>
         <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
         <uses-permission android:name="android.permission.INTERNET"/>
         <uses-permission      android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
      <!-- External storage for caching. -->
         <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <!-- My Location -->
         <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
         <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
      <!-- Maps API needs OpenGL ES 2.0. -->
         <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true"/>
      <!-- End of copy. -->

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme"
            android:hardwareAccelerated="true" >
            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="<YOUR VALUE>"/>
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
            <activity
                android:name="example.gps.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>

そしてxmlファイルは

 <?xml version="1.0" encoding="utf-8"?>
    <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"
    />

ジャバクラスは

   public class MainActivity extends FragmentActivity
        {
           @Override
           protected void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.activity_main);
           }
        }

それは私の問題を解決しました

于 2013-11-12T17:40:43.093 に答える
3

プロジェクトに google-play-services ライブラリ参照を追加してみてください。Eclipse を使用している場合はProject->Properties->AndroidAddgoogle-play-services ライブラリ プロジェクトに移動する必要があります。

あるいは、

project.propertiesファイルを手動で変更できます。google_play_services ライブラリへの参照を追加してみてください。したがって、私のproject.propertiesファイルは次のようになります。

# Project target.
target=android-17
android.library.reference.1=../../../android-sdks/extras/google/google_play_services/libproject/google-play-services_lib

あなたの場合、google-play-services lib へのパスは異なる場合があります

コードをインポートしようとしましたが、同様にクラッシュしました。プロパティ ファイルを変更したとき - マップを実行しています

于 2013-02-06T23:05:39.963 に答える
2

多くの場合、問題はManifest.xml.

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

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

    <permission
        android:name="com.zako.android.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.zako.android.locationapi.maps.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" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.zako.android.locationapi.maps.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="......" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

`

忘れない<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

于 2014-06-03T14:52:17.533 に答える
2

私はこの問題を解決するために多くの時間を費やし、多くの読書と試行の後、

public class MainActivity extends FragmentActivity

このため

public class MainActivity extends android.support.v4.app.FragmentActivity

これがお役に立てば幸いです

于 2013-06-24T01:43:04.683 に答える
1

私にもこのエラーがありましたが、それは外部許可が原因でした。意味がありませんが、この許可を追加してから、すべてが正常に機能しました。

于 2014-05-29T08:08:46.757 に答える
1

次のコード行をonDestroy()

SupportMapFragment mapFragment = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map_location_sharing));

if(mapFragment != null) {
    FragmentManager fM = getFragmentManager();
    fM.beginTransaction().remove(mapFragment).commit();

それは私のために働いた。ありがとう

于 2014-03-13T06:02:24.943 に答える
1

同様のエラーがありましたが、それはこの点から来ていると思います:Google Play Service APIを含めるとき、ワークスペースにコピーせず、元のものを使用します!!!

: ソース ツリーにコピーしたライブラリのコピーを参照する必要があります。Android SDK ディレクトリからライブラリを参照しないでください。

この点を確認してください。

于 2013-02-07T22:40:16.567 に答える
0

API_KEYをマニフェストに追加したところと同じ問題に直面していましたが、すべて問題ありません。

   <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/map_api_key" />
于 2021-05-20T23:17:59.250 に答える