I have a MapsActivity with HeatMap on it. Like Google Maps there is an option to filter data by various categories (like Satellite, Terrain etc in case of Google Maps).
I have a button which brings a modal bottom sheet. This bottom sheet contains a recycler view with a list of categories.
When I click on a category and run a method to make an ArrayList of new filtered data the size turns out to be 0.
Method in MapsActivity class
public void changeHeatMap(int category, int remove){
int count = 0;
if (remove==0) {
ArrayList<LatLng> catHeatMap = new ArrayList<>(3);
while (count < il_cat_data.size()) {
if (il_cat_data.get(count) == category) {
catHeatMap.add(list.get(count));
}
count++;
}
mProvider.setData(catHeatMap);
}else{
mProvider.setData(list);
}
}
OnClick method in the RecyclerView Adapter class
public void onClick(View view) {
int position = getAdapterPosition();
MapsActivity mapsActivity = new MapsActivity();
if (position==MapsActivity.isClicked){
MapsActivity.isClicked = -1;
mapsActivity.changeHeatMap(position,1);
}else{
MapsActivity.isClicked = position;
mapsActivity.changeHeatMap(position,0);
}
}
It throws this error
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.maps.android.heatmaps.HeatmapTileProvider.setData(java.util.Collection)' on a null object reference
While loop is not executed at all in changeHeatMap method and if I put a breakpoint and check size of il_cat_data then it comes out to be 0.
I have checked that data is added in il_cat_data when the app is started. The 'list' is an arraylist which contains complete data and is used to set up the first heatmap.
What can be wrong here? Is data not accessible because of the modal bottom sheet.