我试图在我的应用程序中调用 getMap() 并且总是在该行出现错误
map = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
显示 GoogleMap 的活动是作为片段实现的。有什么问题?我的整个活动如下所示。
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();
}
}}