android - Google maps does not play for some devices and the app crash -


i use code in order instantiate google map :

map = ((mapfragment) getchildfragmentmanager().findfragmentbyid(r.id.map));     mmap = map.getmap();     mmap.setmylocationenabled(true); 

this use work fine many devices such nexus 5 , samsung galaxy s6 have tablet (sony xperia z3) , when try navigate fragment app crash logcat:

fatal exception: main process: com.example.veriah.loneworker, pid: 20646 java.lang.nullpointerexception: attempt invoke virtual method 'void com.google.android.gms.maps.googlemap.setmylocationenabled(boolean)' on null object reference

also have activated locations tablet. know why happening?

thank in advance

try solution :

map.getmapasync(new onmapreadycallback() {                     @override                     public void onmapready(googlemap googlemap) {                         mmap = googlemap;                         googlemap.setmylocationenabled(true);                     }                 }); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -