I'm using this code:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import static com.marcadorfixo.R.id.map;
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(map);
mapFragment.getMapAsync(MainActivity.this);
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng position) {
googleMap.addMarker(
new MarkerOptions().position(position)
);
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng uaua = new LatLng(-9.840318, -39.480388);
googleMap.addMarker(new MarkerOptions()
.position(uaua)
.title("Uauá"));
}
}
Android Studio even compiles, but when trying to run the application it simply stops working.