Я получаю NullPointerException при попытке загрузить карту Google на наше приложение, как below.also Класс Java простирается от AppCompatActivty
и внутри intialiseMap()
мы пытаемся getMap()
Исключение нулевого указателя на addmarker и MarkerOptions на GoogleMap
И здесь где мы получаем исключение, внутри метода placeMarker
public void placeMarker(LatLongDetails user_latlongobj2,
final Context contextPlace) {
try {
if (googlemap == null) {
intialiseMap();
animatecamera(user_latlongobj);
}
if (LoginDetails.Address.length() < 1) {
LoginDetails.Address = "Getting your location .....";
}
//googlemap.clear();
marker = new MarkerOptions().position(
new LatLng(user_latlongobj2.user_latitude,
user_latlongobj2.user_longitude)).title(
LoginDetails.Address);
System.out.println("This is the Address" + LoginDetails.Address);
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
if (googlemap != null) {
googlemap.addMarker(marker).showInfoWindow();
}else {
intialiseMap();
googlemap.addMarker(marker).showInfoWindow();
}
System.out.println("PLACING MARKER" + LoginDetails.Address);
if (marker == null || contextPlace == null) {
Intent in =new Intent(this,ProfileActivity1.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(in);
}
else
fixmarker(marker, contextPlace);
} catch (Exception e) {
fixmarker(marker, contextPlace);
Log.d("Profileactivity", "" + e);
}
}
Это, как мы инициализируем Map
private void intialiseMap() {
try {
if (dialog == null)
dialog = ProgressDialog.show(ProfileActivity1.this, "",
getString(R.string.getting_location), true, true);
}catch(Exception e) {
Log.e("eybaba",""+e);
}
try {
if (googlemap == null) {
googlemap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.mapfragment)).getMap();
googlemap.setInfoWindowAdapter(new CustomInfowindow(context));
// check if map is created successfully or not
if (googlemap == null) {
Toast.makeText(getApplicationContext(),
R.string.maps_create_error, Toast.LENGTH_SHORT)
.show();
}
}
} catch (Exception e) {
}
}
Я предполагаю, что 'intialiseMap (); 'не работает или не возвращает новую карту, и поэтому вызов должен быть' googlemap = intialiseMap(); '. В основном сообщение об ошибке сообщает вам, что не так: 'NullPointerException'. – Thomas
Первое предупреждение показывает, что 'user_longitude' в классе' LatLongDetails' является переменной класса, к которой вы обращаетесь через экземпляр 'user_latlongobj2.user_longitude', но имеет модификатор' static'. Вы можете просто удалить 'static'. – QBrute
@Thomas google = intialiseMap(); дает несовместимые типы error –