SupportMapFragmentManager not resolving

146 Views Asked by At

I am trying to create a SupportMapFragment inside a fragment..I get the following error: The method SupportFragmentManager() is undefined for the type MapFragment

my code is as follows:

import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.GoogleMap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class MapFragment extends Fragment{

     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
       { 
         View v = inflater.inflate(R.layout.fragment_map_view, container, false);
         FragmentManager fm = getFragmentManager();
         FragmentTransaction ft = fm.beginTransaction();
         DateTimeFragment datetime=new DateTimeFragment();
         ft.add(R.id.datetime_container_map, datetime);
         SupportMapFragment mapFragment = (SupportMapFragment)SupportFragmentManager().findFragmentById(R.id.map_fragment);
         return v;
       }

}

However, SupportMapFragmentManager does not resolve. What is the solution to this problem?

2

There are 2 best solutions below

2
On BEST ANSWER

In addition to kalyan pvs's answer, your code is wrong, should look like this:

 SupportMapFragment mapFragment = (SupportMapFragment)getFragmentManager().findFragmentById(R.id.map_fragment);

In your question, you use the method SupportFragmentManager() which doesn't exists. The method getSupportFragmentManager is not available in Fragments, but getFragmentManager will work. This is I guess, because your class already extends the support version of Fragment and therefore getFragmentManager will automatically return the support version of the FragmentManager.

0
On

Check these couple of answers for the problem similar to yours by CommonsWare. Check Answer 1 and Answer 2.

Also, make sure you have Android Private Libraries checked under Properties->Java Build Path->Order and Export. Then clean the project and check if the issue is solved.