Caused by: java.lang.NullPointerException:



  • There's a code.

      package com.perm.kate.api.sample;
    

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.util.Log;
    import android.view.View;

    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
    import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
    import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.CameraPosition;
    import com.google.android.gms.maps.model.LatLng;

    public class MapAct extends FragmentActivity {

    SupportMapFragment mapFragment;
    GoogleMap map;
    final String TAG = "myLogs";

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

    mapFragment = (SupportMapFragment) getSupportFragmentManager()
        .findFragmentById(R.id.map);
    map = mapFragment.getMap();
    if (map == null) {
      finish();
      return;
    }
    init();
    

    }

    private void init() {

    }
    

    public void onClickTest(View view) {
    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    }
    }

    I'm calling him on the second activate.
    He's making such a mistake.

    12-02 13:18:21.672: E/AndroidRuntime(15393): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.perm.kate.api.samp objectle/com.perm.kate.api.sample.MapAct}: java.lang.NullPointerException

    How can that be cured?



  • You need to initiate a google-map object:

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

    For

    mapFragment = (SupportMapFragment) getSupportFragmentManager()
        .findFragmentById(R.id.map);
    map = mapFragment.getMap();
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2