AndroidStudio上的GoogleMap片段活动问题

时间:2015-11-08 19:27:01

标签: android fragment

我在设置googlemap配置时遇到问题。每次我启动应用程序时它总是关闭,因为java.lang.NullPointerException错误。这是示例代码

public class MapsActivity extends Fragment implements GoogleMap.OnMarkerClickListener, android.location.LocationListener {
    public View rootview;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        super.onCreate(savedInstanceState);
        rootview = inflater.inflate(R.layout.activity_about_us, container, false);

        setUpMapIfNeeded();
        _jsonParser = new JSONParser();
        setupGeoCurrentPosition();
        curPos = new LatLng(currentLoc.getLatitude(), currentLoc.getLongitude());

        return rootview;
    }

    private void setUpMapIfNeeded()  {
        if (mMap == null) {
            mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            if (mMap != null)  {
                setUpMap();
            } else if (mMap == null) {
                Toast.makeText(getActivity().getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
            }
        }
    }
}

0 个答案:

没有答案