IEnumFeature not working for Java ArcGIS 10 Add-in

Discussion created by valcannon on Mar 23, 2011
I cannot get IEnumFeature to work for my ArcGIS 10 Add-in that I am writing in Eclipse Java. I think that I am doing it just like the sample code but it always exits on the line where I enumerate the selection (surrounded by message dialogs here). I have eliminated the rest of my code for clarity.

import javax.swing.JOptionPane;
import com.esri.arcgis.addins.desktop.Button;
import com.esri.arcgis.arcmapui.IMxDocument;
import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.carto.ISelection;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.geodatabase.IEnumFeature;
import com.esri.arcgis.interop.AutomationException;

public class ButtonOWD extends Button {

private IApplication app;

@Override public void init(IApplication app){ = app;

public void onClick() throws IOException, AutomationException {
  IMxDocument pMxDoc = (IMxDocument)app.getDocument();
  IMap pMap = pMxDoc.getFocusMap();
  ISelection pSelection = (ISelection) pMap.getFeatureSelection();
  JOptionPane.showMessageDialog(null, "pSelection successfull assigned");
  IEnumFeature pEnumFeature = (IEnumFeature) pSelection;

  JOptionPane.showMessageDialog(null, "enumeration successfull assigned");