MapView onCreate throws NullPointerException on LG devices

前端 未结 1 1959
礼貌的吻别
礼貌的吻别 2021-02-09 00:42

First of all, this problem is for me only reproducible on LG devices (LG G4 and G5) running Android 6. The problem was introduced through the last update of the google play serv

相关标签:
1条回答
  • 2021-02-09 01:10

    You can try to use MapFragment instead of MapView because for updated google play services 11.0.55 not supporting MapView. I used MapView its worked for me.

    Activity class:

        private SupportMapFragment mMapFragment; 
    
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            //return inflater.inflate(R.layout.fragment_find_direction, container, false);
            View view = inflater.inflate(R.layout.fragment_find_direction, null, false);
            SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                    .findFragmentById(R.id.map_fragment);
            mMapFragment.getMapAsync(this);
            mMapFragment = mapFragment;
            return view;
        }
    
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    mMapFragment.onCreate(savedInstanceState);
    }
    

    Xml class:

    <fragment
        class="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/map_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main_lay"
        android:apiKey="@string/google_map_key"
        android:clickable="true"
        android:enabled="true"
        android:focusable="true"
        app:layout_collapseMode="parallax">
    </fragment>
    
    0 讨论(0)
提交回复
热议问题