Binary XML file line #8: Error inflating class fragment, Google Maps

前端 未结 5 1940
醉酒成梦
醉酒成梦 2021-01-12 07:48

In this app, I am trying to add a functional V2 google map. I\'ve looked at most of the tutorials for creating an activity, obtaining a key for the maps, and creating the xm

5条回答
  •  执念已碎
    2021-01-12 08:07

    Try out below code:

    public class ShowActivity extends android.support.v4.app.FragmentActivity {
        private GoogleMap mMap;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_map);
            setUpMapIfNeeded();
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            setUpMapIfNeeded();
        }
    
        private void setUpMapIfNeeded() {
            // Do a null check to confirm that we have not already instantiated the map.
            if (mMap == null) {
                // Try to obtain the map from the SupportMapFragment.
                mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                        .getMap();
                // Check if we were successful in obtaining the map.
                if (mMap != null) {
                    setUpMap();
                }
            }
        }
    }
    

    XML file code:

    
    

    Manifest file code:

        
          
            
          
            
          
    
           
          
              
             
       
    

提交回复
热议问题