I tried to call getMap() in my application and always get error at the line
map = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
The activity for displaying the GoogleMap is implement as a fragment. What could be wrong? My whole activity is shown below.
package sg.SanThit.TrackMe;
import android.annotation.SuppressLint;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MyDetailsFragment extends Fragment {
private TrackerInfo trackerDetailInfo;
GoogleMap map;
public MyDetailsFragment() {
}
@SuppressLint("NewApi")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
map = ((SupportMapFragment)
getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (map == null) {
Toast.makeText(getActivity(), "Google Maps not available",
Toast.LENGTH_LONG).show();
}
}}