2016-04-01 16 views
0

単純なマップフラグメントを実行したかっただけですが、引き続きInflateExceptionが発生しました。私も同様の質問をしましたが、簡単にするために新しいGoogleマッププロジェクトを作成しました。単純なGoogleマッププロジェクトでクラスフラグメントを拡張しているときにエラーが発生しました

04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: FATAL EXCEPTION: main 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: Process: com.example.ali.myapplication, PID: 1785 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ali.myapplication/com.example.ali.myapplication.MapsActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:148) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:5417) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment 

MapsActivity.java:

package com.example.ali.myapplication; 

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

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Sydney and move the camera 
     LatLng sydney = new LatLng(-34, 151); 
     mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    } 
} 

activity_maps.xml:

<LinearLayout 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="#619ec9" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    > 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:map="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/map" tools:context=".MapsActivity" 
     class="com.google.android.gms.maps.SupportMapFragment" 
     tools:layout="@layout/activity_maps" 
     android:layout_width="362dp" 
     android:layout_height="323dp" 
     /> 


</LinearLayout> 

マニフェスト:

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

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

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

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="@string/google_maps_key" /> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 


     <activity 
      android:name=".MapsActivity" 
      android:label="@string/title_activity_maps" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 
+0

小さな再現可能なケースは良いアイデアですが、基本的には同じことを求めているので、あなたの既存の質問を修正することができます。 – halfer

答えて

0

フラグメントはフレームレイアウトに追加する必要があります。直接使用することはできません。 コードを更新して私に知らせてください

+0

お返事ありがとうございました。私はLinearLayoutを追加しましたが、私はまだ同じエラーが発生します –

関連する問題