- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
According to Not able to add ArcGISDynamicMapServiceLayer in Arc
When you don't properly set the proxy parameters you get HttpHostConnectException. How can you catch this connection exception (org.apache.http.conn.HttpHostConnectException) since it's not thrown by JMap class itself. I need to catch this error and take suitable actions or an appropriate warning message about the proxy parameters correctness.
I tried:
MapOptions mapOptions = new MapOptions(MapType.STREETS, 24.43261, -102.92041, 4);
try{
JMap jMap = new JMap(mapOptions);
jMap.setWrapAroundEnabled(true);
}
catch(HttpHostConnectException e){
// Handle error connection due to incorrect proxy parameters
}
But, of course, the compiler claims "Out of Reach try catch clause"
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
First of all, good "catch", by the way.
What happens when you try to catch a general Exception?
This is what works for me. Surround your layer definition code with a try/catch for Exception, instead of a specific one. I know it sounds improper, but this may get you farther along, hopefully?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
Nothing happens, I used:
try{
MapOptions mapOptions = new MapOptions(MapType.STREETS, 24.43261, -102.92041, 4);
JMap jMap = new JMap(mapOptions);
jMap.setWrapAroundEnabled(true);
}
catch(Exception e){
JOptionPane.showMessageDialog(window, "Error connection");
}
It doesn't catch it.
I think the error connection occurs when creating the map because when I debug it, is in this step when the exception is thrown (after 20 seconds). But when I checked the constructor new JMap it doesn't throw any exception.
Please, help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
You could get the exception using the getException() method on the layer. This method could be invoked after the layer has initialized.
dynamicLayer = new ArcGISDynamicMapServiceLayer(URL_DYNAMIC_LAYER);
dynamicLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
System.out.println("Error: " + dynamicLayer.getException());
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
Sorry, could you give me more clues. I couldn't figure out how to use it. Since I don't use DynamicMapServiceLayer, according to my last snippet I tried:
MapOptions mapOptions = new MapOptions(MapType.STREETS, 17.94262710, -95.92216487, 6);
map = new JMap(mapOptions);
map.getLayers().get(0).addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
System.out.println("Error: " + map.getLayers().get(0).getException().getMessage());
}
});Since, after creating, the map the layer[0] is the BaseMapTiled Layer. But I still can't catch the exception, I think that's because at that point the layer doesn't exist due to the connection error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
OK Vijay. You are right. I finally could implement your suggestion. Thanks a lot. Now I'm going to try to accomodate to my app.