0

i've tried all the solutions given in similar question, but still could not eliminate the error in inflating class fragment while using maps. Infact, my code is exactly the same as given in one of the solution of similar question but still the code dosen't run.

----------------------AndroidManifest.xml-------------------------------

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

<uses-sdk
    android:minSdkVersion="12"
    android:targetSdkVersion="21" />
<permission 
 android:name="com.lavisor.mapsdemo.permission.MAPS_RECEIVE"
 android:protectionLevel="signature"/>


<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWoRK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.lavisor.mapsdemo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

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

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

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

</manifest>

-----------------------activity_main.xml-----------------------------

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.lavisor.mapsdemo.MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

</RelativeLayout>

--------------------------activity_map.xml----------------------------------

 <?xml version="1.0" encoding="utf-8"?>
 <fragment 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:map="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
    android:id="@+id/map"
    class="com.google.android.gms.maps.SupportMapFragment"
 />

-------------------MainActivity.xml--------------------------

public class MainActivity extends FragmentActivity {


private static final int GPS_ERRORCODE_CONST = 9001;
GoogleMap mMap;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(servicesOK())
    {
        Toast.makeText(this,"Preparing Map... " , Toast.LENGTH_SHORT).show();

        setContentView(R.layout.activity_map);


    }

    else{
    setContentView(R.layout.activity_main);
    }

 }



 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
 }

//to check if google play services are available on device

 public boolean servicesOK()
 {
    int isAvailable;

    isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if(isAvailable == ConnectionResult.SUCCESS)
    {
        return true;

    }
    else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable))
    {

        Dialog diag = GooglePlayServicesUtil.getErrorDialog(isAvailable,this, GPS_ERRORCODE_CONST);
        diag.show();
    }

    else
    {
        Toast.makeText(this,"Cannot Connect to Google Play Services " , Toast.LENGTH_SHORT).show();
    }
    return false;

   }
}
Kishore L
  • 188
  • 1
  • 14
  • 1
    Possible duplicate of [Google Maps V2 - Error inflating class Fragment](http://stackoverflow.com/questions/14740048/google-maps-v2-error-inflating-class-fragment) – Konstantin Loginov Dec 17 '15 at 16:39
  • It's a duplication of http://stackoverflow.com/questions/14740048/google-maps-v2-error-inflating-class-fragment - it also contains the answer. Good luck! – Konstantin Loginov Dec 17 '15 at 16:40
  • Still dosen't work... i tried all the possible solutions, but same error only – Kishore L Dec 17 '15 at 16:55

2 Answers2

0


you should try using SupportMapFragment instead of MapFragment.

Also, make sure your build.gradle has
com.google.android.gms:play-services-maps:8.3.0


Edit
try use

android:name="com.google.android.gms.maps.SupportMapFragment"
instead of a
class="com.google.android.gms.maps.SupportMapFragment"
michgauz
  • 214
  • 2
  • 10
  • Actually i'm using eclipse, not android studios..and i changed MapFragment to SupportMapFragment.. still not working.. – Kishore L Dec 17 '15 at 16:42
  • Oh ok on Eclipse. Have you imported Google Play Services as Lib Project ? (not only a jar) This point is important. – michgauz Dec 17 '15 at 16:54
  • I tried to run other Google mapV2 example and same error occurs.. please someone help me get through. I downloaded The example map project from --> http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ – Kishore L Dec 18 '15 at 09:15
0

I spent my time reading the logcat error log fully and found that it told me to add this in my manifest file -->>

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

And it worked like a charm... I was searching for a solution for a day .. . but all I had to do was to read the error log fully...

Kishore L
  • 188
  • 1
  • 14