I'm trying to fill a feature layer with graphics but have the problem that when using the FeatureLayer(graphics[]), instruction does not add the graphics to the feature layer. It shows the following
Error "method invocation may produce java.lang.nullpointerexception
I tried assigning a single value to the list level code does not generate any error and graphics list is filled correctly, or have any idea how that can fill a feature layer with a list of graphics?
I attached my code
MapView mMapView;
ArcGISFeatureLayer featurelayerpoints;
FeatureSet variablefeatureset = null;
Graphic[] graficos = new Graphic[listcount];
for (int i = 0; i < listcount; i++) {
Point wgspoint = new Point(routesinfolist[i].Longitude, routesinfolist[i].Latitude);
Point mapPoint = (Point) GeometryEngine.project(wgspoint, SpatialReference.create(4326),
mMapView.getSpatialReference());
Unit mapUnit = mMapView.getSpatialReference().getUnit();
double zoomWidth = Unit.convertUnits(SEARCH_RADIUS, Unit.create(LinearUnit.Code.MILE_US), mapUnit);
attributes.put(String.valueOf(routesinfolist[i].IDOrder), "IDOrder");
graficos[i] = new Graphic(mapPoint, new PictureMarkerSymbol(getResources().getDrawable(R.drawable.circler)), attributes, i);
}
variablefeatureset.setGraphics(graficos);
featurelayerpoints = new ArcGISFeatureLayer(null, variablefeatureset, null);
mMapView.addLayer(featurelayerpoints, 1);
Presently, your FeatureSet variablefeatureset
is set to null
. You need to initialize it using the constructor provided. [docs]
FeatureSet variablefeatureset = new FeatureSet();