java - NullPointerException Google Maps API Android 4.4.4 -
when access activity
shows map on android 4.4.4
device, app crashes, , in logcat
see this:
06-26 11:07:30.211 10977-10977/com.andrey.andreyvedis.iamaref e/androidruntime﹕ fatal exception: main process: com.andrey.andreyvedis.iamaref, pid: 10977 java.lang.runtimeexception: unable start activity componentinfo{com.andrey.andreyvedis.iamaref/com.andrey.andreyvedis.iamaref.poloactivity}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2436) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2495) @ android.app.activitythread.access$900(activitythread.java:170) @ android.app.activitythread$h.handlemessage(activitythread.java:1304) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:146) @ android.app.activitythread.main(activitythread.java:5635) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1291) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1107) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ com.andrey.andreyvedis.iamaref.poloactivity.oncreate(poloactivity.java:54) @ android.app.activity.performcreate(activity.java:5580) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1093) @ android.app.activitythread.performlaunchactivity(activitythread.java:2400) at android.app.activitythread.handlelaunchactivity(activitythread.java:2495) at android.app.activitythread.access$900(activitythread.java:170) at android.app.activitythread$h.handlemessage(activitythread.java:1304) at android.os.handler.dispatchmessage(handler.java:102) at android.os.looper.loop(looper.java:146) at android.app.activitythread.main(activitythread.java:5635) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:515) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1291) at com.android.internal.os.zygoteinit.main(zygoteinit.java:1107) at dalvik.system.nativestart.main(native method)
and part of code have line 54
of code:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_polo); toolbar toolbar = (toolbar) findviewbyid(r.id.app_bar); setsupportactionbar(toolbar); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayhomeasupenabled(true); navigationdrawerfragment drawerfragment = (navigationdrawerfragment) getsupportfragmentmanager().findfragmentbyid(r.id.fragment_navigation_drawer); drawerfragment.setup(r.id.fragment_navigation_drawer,(drawerlayout)findviewbyid(r.id.drawer_layout), toolbar); button btn1 = (button) findviewbyid(r.id.bd1); btn1.setonclicklistener(this); map = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)) .getmap(); marker campo = map.addmarker(new markeroptions() //line 54 .position(campospezia) .title("campo bonanni") .snippet("sei al campo bonanni!") ); // move camera instantly hamburg zoom of 15. map.movecamera(cameraupdatefactory.newlatlngzoom(campospezia, 15)); // zoom in, animating camera. map.animatecamera(cameraupdatefactory.zoomto(10), 2000, null); }
i don't know reason, when launch same activity
on different device uses android 5.1
, works flawlessly. can me?
edit
here's manifest
file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.andrey.andreyvedis.iamaref" android:versioncode="2" android:versionname="1.0.1" > <permission android:name="com.andrey.andreyvedis.iamaref.permission.maps_receive" android:protectionlevel="signature" /> <uses-feature android:glesversion="0x00020000" android:required="true" /> <uses-permission android:name="com.andrey.andreyvedis.iamaref.permission.maps_receive" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.read_external_storage"/> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.access_network_state" /> <!-- 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" /> <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.gms.version" android:value="@integer/google_play_services_version" /> <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> <activity android:name=".introquizactivity" android:label="quiz tecnici"> </activity> <activity android:name=".quizactivity" android:nohistory="true" android:configchanges="orientation|keyboardhidden|screensize" android:label="quiz tecnici" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".resultactivity" android:nohistory="true" android:configchanges="orientation|keyboardhidden|screensize" android:label="risultati" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".subactivity" android:label="@string/title_activity_sub" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".designazioniactivity" android:label="designazioni" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".preparativiactivity" android:configchanges="orientation|keyboardhidden|screensize" android:label="preparativi" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".trovacampiactivity" android:label="trova campi" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".newsactivity" android:label="news" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".modulisticaactivity" android:label="modulistica" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".scadenzeactivity" android:label="scadenze varie" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".poloactivity" android:label="polo allenamenti" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".contattiactivity" android:label="contatti" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".creditiactivity" android:label="crediti" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <activity android:name=".impostazioniactivity" android:label="impostazioni" > <meta-data android:name="android.support.parent_activity" android:value="com.andrey.andreyvedis.iamaref.mainactivity" /> </activity> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasybwj56cmqzcolxgbhufpg9oz_akfc87kpa" /> <activity android:name=".sceltaallenamenti" android:label="scelta allenamenti" > </activity> <activity android:name=".allenamentoestivo" android:label="preparazione estiva" > </activity> <activity android:name=".allenamentosettimanale" android:label="allenamento settimanale" > </activity> </application> </manifest>
here's xml file:
<fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_below="@+id/app_bar" class="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="220dp" />
change following line
map = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)) .getmap();
to
map = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)) .getmap();
here pacakge import
com.google.android.gms.maps.supportmapfragment.
update:
<mapfragment xmlns:android="http://schemas.android.com/apk/res/android"
in above line change mapfragment
fragment
in layout file.
hope helps you.
Comments
Post a Comment