Hello,
I have downloaded the shapefile from this page:
I try to load it to my map by doing that:
File shapefile = new File(System.getProperty("data.dir"), "address");
ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(shapefile.getAbsolutePath());// use the shapefile feature table to create a feature layer
FeatureLayer layer = new FeatureLayer(shapefileFeatureTable);layer.addDoneLoadingListener(() -> {
System.out.println("Layer Loading : " + layer.getLoadStatus());
if (layer.getLoadStatus() == LoadStatus.LOADED) {
mapView.setViewpoint(new Viewpoint(layer.getFullExtent()));
} else {
Platform.runLater(new Runnable() {
@Override
public void run() {
ArcGISRuntimeException loadError = layer.getLoadError();
Throwable Cause = loadError.getCause();
String alertMessage = "(" + layerId + ") '" + portalItemID.title + "' Layer Error : "
+ loadError.getMessage() + (Cause == null ? "" : (" - Cause: " + Cause.getMessage()));
loadError.printStackTrace();
if(Cause != null)
Cause.printStackTrace();
Alert alert = new Alert(AlertType.ERROR, alertMessage);
alert.show();
}
});
}
});
layer.addLoadStatusChangedListener(new LoadStatusChangedListener() {
@Override
public void loadStatusChanged(LoadStatusChangedEvent loadStatusChangedEvent) {
System.out.println("(" + layerId + ") '" + portalItemID.title + "' LoadStatusChangedListener : "+ loadStatusChangedEvent.getNewLoadStatus().name());
}
});
mapView.getMap().getOperationalLayers().add(layer);
But, it doesn't work. I got the following message:
ArcGISRuntimeException: The field already exists.: FID
It also says:
Licensed For Developer Use Only
Would that be the cause?
Thank you for your help?
Your code is basically okay, but there is something odd with that shapefile.
I opened it up in ArcMap and looked at the attributes. It has FID which I would expect, but it also has FID_1. I deleted the attribute completely from the shapefile and this fixed the issue - it loaded fine!
I'm not a shapfile expert, but I'll ask someone to comment on what might have happened here.
I'd also be tempted to ask the data provider what the purpose of the FID_1 attribute is. From the description given of the data I don't believe it should be there.
You also ask why the console has "Licensed For Developer Use Only". This is because you have not licensed your application for deployment. ArcGIS Runtime is free to use as a developer, but there might be a cost associated with deployments. Take a look at License your app—ArcGIS Runtime SDK for Java | ArcGIS for Developers
Does this help?
Thanks Mark, it helps a lot.
How do you alter the shapefile to delete an attribute?
If you have ArcMap or ArcGIS Pro you can edit it.