android - java.lang.NullPointerException: CameraUpdateFactory is not initialized logcat exception -
i'm working google maps. able create , can show google map. want add cameraupdate(latitude, longitude)
. googled , found source code i'm getting nullpointerexception
.
the logcat error message is:
java.lang.nullpointerexception: cameraupdatefactory not initialized
this source. doing wrong?
public class stradacontact extends fragment { public final static string tag = stradacontact.class.getsimplename(); private mapview mmapview; private googlemap mmap; private bundle mbundle; double longitude = 44.79299800000001, latitude = 41.709981; public stradacontact() { } public static stradacontact newinstance() { return new stradacontact(); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.strada_contact, container,false); mmapview = (mapview) rootview.findviewbyid(r.id.pointmap); mmapview.oncreate(mbundle); setupmapifneeded(rootview); return rootview; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mbundle = savedinstancestate; } private void setupmapifneeded(view inflatedview) { if (mmap == null) { mmap = ((mapview) inflatedview.findviewbyid(r.id.pointmap)).getmap(); if (mmap != null) { cameraupdate center = cameraupdatefactory.newlatlng(new latlng(latitude, longitude)); cameraupdate zoom = cameraupdatefactory.zoomto(15); mmap.movecamera(center); mmap.animatecamera(zoom); } } } @override public void onresume() { super.onresume(); mmapview.onresume(); } @override public void onpause() { super.onpause(); mmapview.onpause(); } @override public void ondestroy() { mmapview.ondestroy(); super.ondestroy(); }
}
<com.google.android.gms.maps.mapview android:id="@+id/pointmap" android:name="com.google.android.gms.maps.mapfragment" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.mapfragment" />
try in "oncreate":
try { mapsinitializer.initialize(this); } catch (googleplayservicesnotavailableexception e) { e.printstacktrace(); }
Comments
Post a Comment