Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method getFragmentManager() is undefined for the type MainActivity

I am trying to implement Google Map in android using Google API, but I am getting the error

The method getFragmentManager() is undefined for the type MainActivity

the whole MainActivity code is as follows:

public class MainActivity extends Activity {

private GoogleMap map;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

  }
}
like image 553
user3217746 Avatar asked Jan 21 '14 05:01

user3217746


1 Answers

Fragments were available from Honey Comb onwards and hence your target API shall >= 11

If you want to use fragments to older versions of android you shall use android support v7 library. And in that case your MainActivity shall extend ActionBarActivity, instead of Activity.

If you are using android support v4, your MainActivity shall extend FragmentActivity and you will need to call getSupportFragmentManager() instead of getFragmentManager()

I hope it helps!

like image 71
Vivek Soneja Avatar answered Nov 09 '22 20:11

Vivek Soneja