trancer
trancer

Reputation: 155

Google Maps is showing an error on compile

When I try to compile my APK I'm getting the following error:

mMapFragment = new SupportMapFragment() {

Explanation for issues of type "ValidFragment": From the Fragment documentation: Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment with getArguments().

Any help is appreciated.

I guess this is causing that error:

This is within a Fragment:

 mMapFragment = new SupportMapFragment() {

            @Override
            public void onActivityCreated(Bundle savedInstanceState) {
                super.onActivityCreated(savedInstanceState);

           }
        };

Logcat does not show anything..

Thanks

Upvotes: 0

Views: 184

Answers (1)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Kindly double check you code implementation:

SupportMapFragment

A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs. Being a fragment, this component can be added to an activity's layout file simply with the XML below.

A GoogleMap must be acquired using getMapAsync(OnMapReadyCallback). This class automatically initializes the maps system and the view. A view can be removed when the SupportMapFragment's onDestroyView() method is called and the useViewLifecycleInFragment(boolean) option is set. When this happens the SupportMapFragment is no longer valid until the view is recreated again later when SupportMapFragment's onCreateView(LayoutInflater, ViewGroup, Bundle) method is called.

Any objects obtained from the GoogleMap is associated with the view. It's important to not hold on to objects (e.g. Marker) beyond the view's life. Otherwise it will cause a memory leak as the view cannot be released.

To use this class, you must include the Android support library in your build path.

You can also check out the answers in these SO questions : How to put Google Maps V2 on a Fragment Using ViewPager and Add Google Maps API V2 in a fragment

Upvotes: 1

Related Questions