I have a very simple example of an instance for creating a IconGenerator and make it visible on the map.
The problem is that it gives me a NullPointerException each time it wants to create the IconGenerator iconita = new IconGenerator(getContext());
public class Controller {
GoogleMap mMap;
Context context;
private static Controller instance;
private Controller() {
}
public static Controller getInstance() {
if (instance == null) {
instance = new Controller();
}
return instance;
}
public void setContext() {
this.context = context;
}
public Context getContext() {
return context;
}
public Map<String, List<Marker>> adaugaRuta(ShowTheRute theRoute) {
Map<String, List<Marker>> objectMap = new HashMap<>();
IconGenerator iconita = new IconGenerator(getContext()); <-- HERE it gives NullPointerException
iconita.setContentPadding(5, -5, 5, -5);
iconita.setRotation(-270);
iconita.setContentRotation(270);
Bitmap iconbit = iconita.makeIcon("Marker 1.");
final Marker mae = mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(iconbit)).position(new LatLng(46.762035, 23.597659)).anchor(0f, 0.5f));
mae.isVisible();
List<Marker> marker1 = new ArrayList<>();
marker1.add(mae);
objectMap.put("marker1", marker1);
theRoute.getTheRute(objectMap);
return objectMap;
}
}