android - Why I can't get google map V2 working -
i can't load basic google map v2 in phone.
coding according website , got api key.
program still didn't work.this give below error
error
07-22 13:02:24.630: e/androidruntime(5323): fatal exception: main 07-22 13:02:24.630: e/androidruntime(5323): java.lang.runtimeexception: unable start activity componentinfo{com.example.googlemap/com.example.googlemap.mainactivity}: android.view.inflateexception: binary xml file line #17: error inflating class fragment 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activitythread.performlaunchactivity(activitythread.java:1651) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1667) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activitythread.access$1500(activitythread.java:117) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activitythread$h.handlemessage(activitythread.java:935) 07-22 13:02:24.630: e/androidruntime(5323): @ android.os.handler.dispatchmessage(handler.java:99) 07-22 13:02:24.630: e/androidruntime(5323): @ android.os.looper.loop(looper.java:130) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activitythread.main(activitythread.java:3691) 07-22 13:02:24.630: e/androidruntime(5323): @ java.lang.reflect.method.invokenative(native method) 07-22 13:02:24.630: e/androidruntime(5323): @ java.lang.reflect.method.invoke(method.java:507) 07-22 13:02:24.630: e/androidruntime(5323): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:912) 07-22 13:02:24.630: e/androidruntime(5323): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:670) 07-22 13:02:24.630: e/androidruntime(5323): @ dalvik.system.nativestart.main(native method) 07-22 13:02:24.630: e/androidruntime(5323): caused by: android.view.inflateexception: binary xml file line #17: error inflating class fragment 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:581) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.rinflate(layoutinflater.java:623) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.inflate(layoutinflater.java:408) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.inflate(layoutinflater.java:320) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.inflate(layoutinflater.java:276) 07-22 13:02:24.630: e/androidruntime(5323): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:235) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activity.setcontentview(activity.java:1663) 07-22 13:02:24.630: e/androidruntime(5323): @ com.example.googlemap.mainactivity.oncreate(mainactivity.java:11) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1050) 07-22 13:02:24.630: e/androidruntime(5323): @ android.app.activitythread.performlaunchactivity(activitythread.java:1615) 07-22 13:02:24.630: e/androidruntime(5323): ... 11 more 07-22 13:02:24.630: e/androidruntime(5323): caused by: java.lang.classnotfoundexception: android.view.fragment in loader dalvik.system.pathclassloader[/data/app/com.example.googlemap-1.apk] 07-22 13:02:24.630: e/androidruntime(5323): @ dalvik.system.pathclassloader.findclass(pathclassloader.java:240) 07-22 13:02:24.630: e/androidruntime(5323): @ java.lang.classloader.loadclass(classloader.java:551) 07-22 13:02:24.630: e/androidruntime(5323): @ java.lang.classloader.loadclass(classloader.java:511) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.createview(layoutinflater.java:471) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.oncreateview(layoutinflater.java:549) 07-22 13:02:24.630: e/androidruntime(5323): @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:66) 07-22 13:02:24.630: e/androidruntime(5323): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:568) 07-22 13:02:24.630: e/androidruntime(5323): ... 20 more
manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.googlemap" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <permission android:name = "com.examaple.googlemap.permission.maps_receive" android:protectionlevel="signature"/> <uses-permission android:name ="com.example.googlemap.permission.maps_receive"/> <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.google.android.providers.gsf.permission.read_gservices"/> <!-- following 2 permissions not required use google maps android api v2, recommended. --> <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" > <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasyac8wx3virczuu7yg6xl1p5rfhlpz3do2q"/> <activity android:name="com.example.googlemap.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> </application> </manifest>
layout :- 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=".mainactivity" > <textview android:id="@+id/header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <fragment android:id="@+id/map" android:layout_below="@+id/header" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.mapfragment"/> </relativelayout>
mainactivity.java
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } }
your min sdk in 8. should use supportmapfragment
<fragment class="com.google.android.gms.maps.supportmapfragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent"/>
your activity must extend fragmentactivity
.
make sure have added support library
also make sure imported below
import android.support.v4.app.fragmentactivity; import com.google.android.gms.maps.supportmapfragment;
make sure have referenced google play services library project.
you can download sdk manager , follow suggestion in below link.
importing google-play-service library showing red x next reference android
as side note if have updated adt rev 22 make sure check android private libraries in oerder export tab of java build path.clean , build. ignore if not required.
also make sure have enabled google maps android in services tab of gogle api console.
Comments
Post a Comment