eclipse - Android google Map Api V2 Crashes on runtime -
i trying add map fragment android layout using google map api v2. have followed several tutorials, 1 google has , has been pointed post here. app crashes after starting layout. files are
manifest (in [my key] there actual key google console using debug code , package name:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.publicthreadsmap" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <permission android:name="com.example.publicthreadsmap.permission.maps_receive" android:protectionlevel="signature"/> <uses-permission android:name="com.example.publicthreadsmap.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" > <uses-library android:name="com.google.android.maps"/> <activity android:name="com.example.publicthreadsmap.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="[my key]"/> </activity> </application> </manifest>
layout:
<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" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="23dp" android:text="test" /> <fragment android:id="@+id/map" android:layout_below="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" class="com.google.android.gms.maps.supportmapfragment"/> </relativelayout>
and java file :
package com.example.publicthreadsmap; import android.os.bundle; import android.support.v4.app.fragmentactivity; public class mainactivity extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } }
i have copied (import) google-play-service-lib in workspace , referenced map project.
have referenced v4 android support jar.
logcat massages:
05-04 10:19:56.284: e/androidruntime(21660): fatal exception: main 05-04 10:19:56.284: e/androidruntime(21660): java.lang.runtimeexception: unable start activity componentinfo{com.example.publicthreadsmap/com.example.publicthreadsmap.mainactivity}: android.view.inflateexception: binary xml file line #18: error inflating class fragment 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activitythread.performlaunchactivity(activitythread.java:1968) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1993) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activitythread.access$600(activitythread.java:127) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activitythread$h.handlemessage(activitythread.java:1159) 05-04 10:19:56.284: e/androidruntime(21660): @ android.os.handler.dispatchmessage(handler.java:99) 05-04 10:19:56.284: e/androidruntime(21660): @ android.os.looper.loop(looper.java:137) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activitythread.main(activitythread.java:4507) 05-04 10:19:56.284: e/androidruntime(21660): @ java.lang.reflect.method.invokenative(native method) 05-04 10:19:56.284: e/androidruntime(21660): @ java.lang.reflect.method.invoke(method.java:511) 05-04 10:19:56.284: e/androidruntime(21660): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:978) 05-04 10:19:56.284: e/androidruntime(21660): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:745) 05-04 10:19:56.284: e/androidruntime(21660): @ dalvik.system.nativestart.main(native method) 05-04 10:19:56.284: e/androidruntime(21660): caused by: android.view.inflateexception: binary xml file line #18: error inflating class fragment 05-04 10:19:56.284: e/androidruntime(21660): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:697) 05-04 10:19:56.284: e/androidruntime(21660): @ android.view.layoutinflater.rinflate(layoutinflater.java:739) 05-04 10:19:56.284: e/androidruntime(21660): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-04 10:19:56.284: e/androidruntime(21660): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-04 10:19:56.284: e/androidruntime(21660): @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-04 10:19:56.284: e/androidruntime(21660): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:272) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activity.setcontentview(activity.java:1835) 05-04 10:19:56.284: e/androidruntime(21660): @ com.example.publicthreadsmap.mainactivity.oncreate(mainactivity.java:12) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activity.performcreate(activity.java:4469) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1052) 05-04 10:19:56.284: e/androidruntime(21660): @ android.app.activitythread.performlaunchactivity(activitythread.java:1932) 05-04 10:19:56.284: e/androidruntime(21660): ... 11 more 05-04 10:19:56.284: e/androidruntime(21660): caused by: java.lang.runtimeexception: api key not found. check in element of androidmanifest.xml 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.ab.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.ab.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.ab.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.ag.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.ag.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.bw.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ maps.z.r.oncreateview(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.maps.internal.imapfragmentdelegate$stub.ontransact(imapfragmentdelegate.java:107) 05-04 10:19:56.284: e/androidruntime(21660): @ android.os.binder.transact(binder.java:297) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.maps.internal.imapfragmentdelegate$a$a.oncreateview(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.maps.supportmapfragment$a.oncreateview(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.internal.e$4.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.internal.e.a(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.internal.e.oncreateview(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ com.google.android.gms.maps.supportmapfragment.oncreateview(unknown source) 05-04 10:19:56.284: e/androidruntime(21660): @ android.support.v4.app.fragment.performcreateview(fragment.java:1460) 05-04 10:19:56.284: e/androidruntime(21660): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:884) 05-04 10:19:56.284: e/androidruntime(21660): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1066) 05-04 10:19:56.284: e/androidruntime(21660): @ android.support.v4.app.fragmentmanagerimpl.addfragment(fragmentmanager.java:1168) 05-04 10:19:56.284: e/androidruntime(21660): @ android.support.v4.app.fragmentactivity.oncreateview(fragmentactivity.java:280) 05-04 10:19:56.284: e/androidruntime(21660): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:669) 05-04 10:19:56.284: e/androidruntime(21660): ... 21 more
your error:
e/androidruntime(21660): java.lang.runtimeexception: unable start activity componentinfo{com.example.publicthreadsmap/com.example.publicthreadsmap.mainactivity}: android.view.inflateexception: binary xml file line #18: error inflating class fragment
indicates there problem inflating class fragment, happens when supportmapfragment
class not found. leads me think did not referenced google-play-services
correctly.
please read first 3 steps of blog post , make sure doing it's correctly, , have green v next referencing in properties window:
update:
now see problem, change this:
<application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.publicthreadsmap.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="[my key]"/> </activity> </application>
to this:
<application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.publicthreadsmap.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="[my key]"/> </application>
look @ location of last activity
tag. meta-data
tag should appear right before closing application
tag.
Comments
Post a Comment