Error inflating class fragment in MapFragment

android, google-maps

Solution

Use:

XML:

<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
         />

Class

GoogleMap mMap;
SupportMapFragment mapFrag;

Now set it:

if (mMap == null) {
            mapFrag= (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
            mMap =  mapFrag.getMap();

            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                // The Map is verified. It is now safe to manipulate the map.

            }
        }

Also add this meta Tag within in manifest file.

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

Problem

I have xml file with my MapFragment ``` <?xml version="1.0" encoding="utf-8"?> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" /> ``` And Fragment using it : ``` public class CallistoMapFragment extends MapFragment { private GoogleMap mMap; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.map_fragment, null); mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap(); setUpMap(); return v; } private void setUpMap() { mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title( "Marker")); } ``` } When trying to compile get error 11-20 15:31:15.343: E/AndroidRuntime(10705): android.view.InflateException: Binary XML file line #6: Error inflating class fragment API key in android manifest is right. What wrong?

Original source