android - Error inflating class fragment while trying to use Google Maps -
i'm trying run simple demo app of google maps. i've referred standard article.
but i'm getting error inflating class fragment exception.
i've updated mt manifest properly. registered map api key. install google-play-services , linked current project. extended activity fragmentactivity, still doesn't work.
am doing wrong?
i referred error inflating class fragment no avail. appreciated.
my code follows: 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" tools:context=".mainactivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.mapfragment" /> </relativelayout>
mainactivity.java
package com.android.googlemapsdemo; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.widget.toast; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.marker; import com.google.android.gms.maps.model.markeroptions; public class mainactivity extends fragmentactivity { static final latlng hamburg = new latlng(53.558, 9.927); static final latlng kiel = new latlng(53.551, 9.993); private googlemap map; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); map = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)) .getmap(); if (map != null) { marker hamburg = map.addmarker(new markeroptions() .position(hamburg).title("hamburg")); marker kiel = map.addmarker(new markeroptions() .position(kiel) .title("kiel") .snippet("kiel cool") .icon(bitmapdescriptorfactory .fromresource(r.drawable.ic_launcher))); // move camera instantly hamburg zoom of 15. map.movecamera(cameraupdatefactory.newlatlngzoom(hamburg, 15)); // zoom in, animating camera. map.animatecamera(cameraupdatefactory.zoomto(10), 2000, null); } else { map = ((mapfragment) getfragmentmanager() .findfragmentbyid(r.id.map)).getmap(); if (map == null) { toast.maketext(mainactivity.this, "unable generate map", toast.length_short).show(); } } } }
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.googlemapsdemo" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="11" android:targetsdkversion="19" /> <permission android:name="com.android.googlemapsdemo.permission.maps_receive" android:protectionlevel="signature" /> <uses-feature android:glesversion="0x00020000" android:required="true" /> <uses-permission android:name="com.android.googlemapsdemo.permission.maps_receive" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.android.googlemapsdemo.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="aizasyat9_v5yi-7cmf_yta0y_zedfpzeh5xfl0" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application> </manifest>
change
<uses-sdk android:minsdkversion="11"
to
<uses-sdk android:minsdkversion="12"
if have 11 using supportmapfragment
. consider this
https://developer.android.com/about/dashboards/index.html?utm_source=ausdroid.net
looking @ link better change 12
change
public class mainactivity extends fragmentactivity
to
public class mainactivity extends activity
also getmap()
can return null. better check availability of google map services.
you missing
<uses-permission android:name="android.permission.access_network_state"/>
in manifest file
you can remove
<permission android:name="com.android.googlemapsdemo.permission.maps_receive" android:protectionlevel="signature" />
and this
<uses-permission android:name="com.android.googlemapsdemo.permission.maps_receive" />
Comments
Post a Comment