0

Well, i'm trying to add google map to my application but i'm having those errors

04-17 16:25:07.169: E/AndroidRuntime(8592): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
 04-17 16:25:07.169: E/AndroidRuntime(8592): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.guide_oran-1.apk]

My main activity :

package com.example.guide_oran;

import android.app.Activity;
import android.os.Bundle;

public class Activity_map extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.gmap);
    }
}

my xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    class="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
 />
Luca Sepe
  • 2,435
  • 1
  • 20
  • 26
choco
  • 255
  • 1
  • 7
  • 14

2 Answers2

1

It might be caused by your Activity extension and your layout which has only a fragment class. You need to extend your activity with FragmentActivity to allow the activity to deal with fragments. That being said, you also need to change your fragment class to support SupportMapFragment.

public class Activity_map extends FragmentActivity {
    GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.gmap);
       // find the fragment and commit it into this activity
       SupportMapFragment mapfragment = (SupportMapFragment) 
                    getSupportFragmentManager().findFragmentById(R.id.map);
       // initialization of googlemap
       googleMap = mapfragment.getMap();

       // It might be resumed by:
       // googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    }
}  

Then instead of class="com...MapFragment", you need to change the class of the fragment to:

android:name="com.google.android.gms.maps.SupportMapFragment"

You can see multiple tips for the same issue on: Unable instantiate android.gms.maps.MapFragment
Also, find a complete and detailed answer to use Google Maps, step by step.

Community
  • 1
  • 1
Blo
  • 11,903
  • 5
  • 45
  • 99
0

Try to put your fragment inside a Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

   <fragment
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      class="com.google.android.gms.maps.MapFragment" />

</RelativeLayout>

Here you can found a good tutorial

Luca Sepe
  • 2,435
  • 1
  • 20
  • 26