2017-09-26 2 views
0

Bien que je carte de configuration d'abord l'activité de fragmenter donne une erreur que je ne comprends pas, je vérifie le code XML pour nom propre mais il me donne une erreurCarte Fragment inflation Erreur

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #4: Error inflating class fragment 

MainActivity.class

public class MainActivity extends FragmentActivity implements OnMapReadyCallback{ 

    GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Sydney, Australia, 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_main.xml

<?xml version="1.0" encoding="utf-8"?> 

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/map" 
android:name="com.volxom.nearbyalerts.activities.MainActivity" 
android:layout_width="match_parent" 
android:layout_height="match_parent" /> 
+0

Pouvez-vous poster votre XML – UltimateDevil

+0

oui vous je suis dessus –

+0

@MuhammadAli Montre ton xml. –

Répondre

4

Vous devez utiliser SupportMapFragment dans l'attribut name.

class="com.google.android.gms.maps.SupportMapFragment" 

Votre XML devrait ressembler à ceci:

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

Vous devriez avoir dans votre manifeste:

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

Référence: https://developers.google.com/android/reference/com/google/android/gms/maps/SupportMapFragment

+0

même problème @Bhuvanesh Bs –

+0

encore le même problème –

+0

@MuhammadAli essayer avec' class = "com.google.android.gms.maps.SupportMapFragment" ' –