Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to set up an info table in an addin for ArcGIS 10. I'm using Java and Eclipse IDE. The code I have is here:

public class Tables {

String database = "C:\\GIS";
String nameOfTable = "getOn";
public ITable createInfoTable(String database, String nameOfTable) throws IOException  {



        IPropertySet propertySet = new PropertySet();
        propertySet.setProperty("DATABASE", database);



        IWorkspaceFactory workspaceFactory = new ArcInfoWorkspaceFactory();



        IArcInfoWorkspace workspace = (IArcInfoWorkspace)workspaceFactory.open( propertySet, 0);

        //Fails here (or above actually)  Check out Factory.open


        IArcInfoItems arcInfoItems = new ArcInfoItems();
        ITable  myTable = workspace.createInfoTable("myTable", arcInfoItems);


        return myTable;

I've adapted this code from C# as there are no examples on the Arc pages for Java. You can see with the comment where it is failing. If you can see what's going wrong please let me know. And I will repost if I crack it. (see here for original C# example: http://resources.esri.com/help/9.3/ArcGISEngine/ArcObjects/esriDataSourcesFile/IArcInfoWorkspace.CreateInfoTable_Example.htm)

share|improve this question
    
It would help to know the error. –  Chaz Apr 11 '12 at 13:53
    
you're right there Chaz. Unspecified error is all it gives me. –  Oliver Burdekin Apr 11 '12 at 20:58

2 Answers 2

Okay, I've worked around this in a different way. I'll put everything in to help others out. Firstly I needed a workspace object which can be returned as follows:

    static IWorkspace openWorkspace(String pathToFile)throws Exception
{
    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
    return  workspaceFactory.openFromFile(pathToFile, 0);

}

Following that it was table building time. I've adapted the following code from a C# snippet I found online. Instead of asking for an IWorkspace2 object this javised version asks for an IWorkspace object. There's not a lot of other differences apart from casting the workspace object later on in order to use the IWorkspace2 interface briefly and slight changes to the checkFields inputs.The IGeoprocessor bit is just me trying to find the current workspace of the user which can then obviously be passed to the method above.

public ITable createTable(IWorkspace workspace, String nameOfTable, IFields fields) throws Exception  {

    System.out.println("" + openWorkspace("C:\\GIS\\Test.gdb"));
    /*
    IGeoProcessor geop = new GeoProcessor();
    String userWkSp = (String) geop.getEnvironmentValue("workspace");


    System.out.println("user workpace = " + userWkSp);
    */
      // create the behavior clasid for the featureclass
      UID uid = new UID();

      if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

      IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // Explicit Cast
      ITable table;

      System.out.println("Got this far");
      IWorkspace2 wkSp2 = (IWorkspace2) workspace;
      if (wkSp2.isNameExists(esriDatasetType.esriDTTable, nameOfTable))
      {
        // table with that name already exists return that table 
        table = featureWorkspace.openTable(nameOfTable);
        return table;
      }

      uid.setValue("esrigeodatabase.Object");

      IObjectClassDescription objectClassDescription = new ObjectClassDescription();

      // if a fields collection is not passed in then supply our own
      if (fields == null)
      {
        // create the fields using the required fields method
        fields = objectClassDescription.getRequiredFields();
        IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Explicit Cast

        IField field = new Field();

        // create a user defined text field
        IFieldEdit fieldEdit = (IFieldEdit)field; // Explicit Cast

        // setup field properties
        fieldEdit.setName("SampleField");
        fieldEdit.setType(esriFieldType.esriFieldTypeString);

        fieldEdit.setAliasName("Sample Field Column");
        fieldEdit.setDefaultValue("test");

        fieldEdit.setLength(100);

        // add field to field collection
        fieldsEdit.addField(field);
        fields = (IFields)fieldsEdit; // Explicit Cast
      }
      // Use IFieldChecker to create a validated fields collection.
      IFieldChecker fieldChecker = new FieldChecker();
      IEnumFieldError enumFieldError[] = null;
      IFields validatedFields[] = null;

      fieldChecker.setValidateWorkspaceByRef((IWorkspace)workspace);
      fieldChecker.validate(fields, enumFieldError,  validatedFields);

      // The enumFieldError enumerator can be inspected at this point to determine 
      // which fields were modified during validation.


      // create and return the table
      table = featureWorkspace.createTable(nameOfTable, fields, uid, uid, "");



    return table;
    }
share|improve this answer

I think you need to cast the arcInfoItems to IArcInfoItemsEditProxy and call addItem to add items (aka fields) to the table.

Each item is defined using IArcInfoItemEdit.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.