android - Trying to get map from fragmentManager always return null -
i'm trying android applications uses viewpager. in third page have map instantiate inside xml of fragment:
<?xml version="1.0" encoding="utf-8"?> <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" android:orientation="vertical"> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" class="com.google.android.gms.maps.supportmapfragment" /> ... </relativelayout>
so when try map after onstart() of class extends fragment id of map nullpointerexception.
public void onstart() { supportmapfragment mapfragment = (supportmapfragment) getfragmentmanager().findfragmentbyid(r.id.map); mmap = mapfragment.getmap(); esperandoloc.setvisibility(view.visible); inicialitzarloc(); fragmentmap = this; if (mmap== null) { toast.maketext(getactivity(),"google maps not available", toast.length_long).show(); } }
debuggin found out fragmentmanager correctly containing 5 fragments of viewpager fragment of map inside 1 not there.
any idea of how can map correctly? thank you.
edit forgotten inflate fragment contains map in oncreate() inside fragment class:
public view oncreateview(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_mapa, container, false);
the logcat error obtain after running next one:
05-18 20:41:29.725: e/androidruntime(20636): fatal exception: main 05-18 20:41:29.725: e/androidruntime(20636): process: com.example.app, pid: 20636 05-18 20:41:29.725: e/androidruntime(20636): java.lang.nullpointerexception 05-18 20:41:29.725: e/androidruntime(20636): @ fragments.mapatab.inicialitzarmapa(mapatab.java:113) 05-18 20:41:29.725: e/androidruntime(20636): @ fragments.mapatab.inicialitzarloc(mapatab.java:108) 05-18 20:41:29.725: e/androidruntime(20636): @ fragments.mapatab.onactivitycreated(mapatab.java:90) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:892) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1083) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:635) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1431) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:431) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.view.viewpager.populate(viewpager.java:895) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:469) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:441) 05-18 20:41:29.725: e/androidruntime(20636): @ android.support.v4.view.viewpager.setcurrentitem(viewpager.java:422) 05-18 20:41:29.725: e/androidruntime(20636): @ com.example.app.mainactivity.ontabselected(mainactivity.java:136) 05-18 20:41:29.725: e/androidruntime(20636): @ com.android.internal.app.actionbarimpl.selecttab(actionbarimpl.java:577) 05-18 20:41:29.725: e/androidruntime(20636): @ com.android.internal.app.actionbarimpl$tabimpl.select(actionbarimpl.java:1105) 05-18 20:41:29.725: e/androidruntime(20636): @ com.android.internal.widget.scrollingtabcontainerview$tabclicklistener.onclick(scrollingtabcontainerview.java:547) 05-18 20:41:29.725: e/androidruntime(20636): @ android.view.view.performclick(view.java:4438) 05-18 20:41:29.725: e/androidruntime(20636): @ android.view.view$performclick.run(view.java:18422) 05-18 20:41:29.725: e/androidruntime(20636): @ android.os.handler.handlecallback(handler.java:733) 05-18 20:41:29.725: e/androidruntime(20636): @ android.os.handler.dispatchmessage(handler.java:95) 05-18 20:41:29.725: e/androidruntime(20636): @ android.os.looper.loop(looper.java:136) 05-18 20:41:29.725: e/androidruntime(20636): @ android.app.activitythread.main(activitythread.java:5017) 05-18 20:41:29.725: e/androidruntime(20636): @ java.lang.reflect.method.invokenative(native method) 05-18 20:41:29.725: e/androidruntime(20636): @ java.lang.reflect.method.invoke(method.java:515) 05-18 20:41:29.725: e/androidruntime(20636): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 05-18 20:41:29.725: e/androidruntime(20636): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 05-18 20:41:29.725: e/androidruntime(20636): @ dalvik.system.nativestart.main(native method)
Comments
Post a Comment