I keep getting java.util.concurrent.ExecutionException: com.esri.arcgisruntime.ArcGISRuntimeException: Cannot call this method in this context for the tableQueryResult.get(); Any clue why?
Thanks in Advance.
private void queryFeaturesFromTable() {
ServiceFeatureTable table = new ServiceFeatureTable(
"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
table.loadAsync();
table.addDoneLoadingListener(() -> {
QueryParameters query = new QueryParameters();
query.setWhereClause("1=1");
query.setReturnGeometry(true);
ListenableFuture<FeatureQueryResult> tableQueryResult = table.queryFeaturesAsync(query);
tableQueryResult.addDoneListener(() -> {
try {
List<Graphic> graphics = new ArrayList<>();
FeatureQueryResult result = tableQueryResult.get();
result.forEach(feature -> {
graphics.add(new Graphic(feature.getGeometry()));
});
} catch (ExecutionException | InterruptedException e) {
System.out.println("Error querying Service Table: " + e);
}
});
});
}
Can you share more of your code? It works fine for me as follows:
import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.data.FeatureQueryResult;
import com.esri.arcgisruntime.data.QueryParameters;
import com.esri.arcgisruntime.data.ServiceFeatureTable;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.MapView;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class GetQueryResultsRuntime extends Application {
private MapView mapView;
@Override
public void start(Stage stage) throws Exception {
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
stage.setTitle("Display Map Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
ArcGISMap map = new ArcGISMap(Basemap.createImagery());
mapView = new MapView();
mapView.setMap(map);
stackPane.getChildren().addAll(mapView);
Button button = new Button("Query");
button.setOnAction(event -> {
queryFeaturesFromTable();
});
StackPane.setAlignment(button, Pos.BOTTOM_RIGHT);
StackPane.setMargin(button, new Insets(15));
stackPane.getChildren().add(button);
}
@Override
public void stop() {
if (mapView != null) {
mapView.dispose();
}
}
private void queryFeaturesFromTable() {
ServiceFeatureTable table = new ServiceFeatureTable(
"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0");
table.loadAsync();
table.addDoneLoadingListener(() -> {
QueryParameters query = new QueryParameters();
query.setWhereClause("1=1");
query.setReturnGeometry(true);
ListenableFuture<FeatureQueryResult> tableQueryResult = table.queryFeaturesAsync(query);
tableQueryResult.addDoneListener(() -> {
try {
List<Graphic> graphics = new ArrayList<>();
FeatureQueryResult result = tableQueryResult.get();
result.forEach(feature -> {
graphics.add(new Graphic(feature.getGeometry()));
});
System.out.printf("%d graphics\n", graphics.size());
} catch (ExecutionException | InterruptedException e) {
System.out.println("Error querying Service Table: " + e);
}
});
});
}
public static void main(String[] args) {
Application.launch(args);
}
}
Thank you Gary for your response. I copy pasted your code in my IDE and tried running it. I ran the code and the application window showed up. On clicking the query button, I still get the same error
Error querying Service Table: java.util.concurrent.ExecutionException: com.esri.arcgisruntime.ArcGISRuntimeException: Cannot call this method in this context
My console output is :
Initializing...
Java version : 1.8.0_191 (Oracle Corporation) x86_64
Error querying Service Table: java.util.concurrent.ExecutionException: com.esri.arcgisruntime.ArcGISRuntimeException: Cannot call this method in this context
I am using Eclipse with Java 8 and downloaded the java sdk and have the following dependencies added
arcgis-runtime-sdk-java-100.4.0/libs/arcgis-java-api-javadoc.jar
arcgis-runtime-sdk-java-100.4.0/libs/arcgis-java-api.jar
arcgis-runtime-sdk-java-100.4.0/libs/commons-codec-1.11.jar
arcgis-runtime-sdk-java-100.4.0/libs/commons-logging-1.2.jar
arcgis-runtime-sdk-java-100.4.0/libs/gson-2.8.5.jar
Is something wrong with my config?
Thanks