1

I am trying to update my feature class with some new parameters using IEditWorkSpace, Following is my code ---

 IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
 IWorkspace workspace = new Workspace(workspaceFactory.openFromFile(inGDB, 0));

   IFeatureWorkspace ifw = (IFeatureWorkspace) workspace;
   IWorkspaceEdit iwe = (IWorkspaceEdit)workspace;
    iwe.startEditing(true);
    iwe.startEditOperation();

       IFeatureClass ifetclass =  ifw.openFeatureClass("CPWire");
       IFeatureCursor ifc = ifetclass.search(null, true);
       int field = ifc.findField("CREATIONUSER");
       System.out.println("CREATIONUSER :"+field);
       IFeature iff = ifc.nextFeature();
            while((iff = ifc.nextFeature()) != null)
            {
           iff.setValue(field, "xyz");
           iff.store();
       }
   iwe.stopEditOperation();
   iwe.stopEditing(true);    
  }

While executing my code I get following error

Objects in this class cannot be updated outside an edit session 

Why am I getting this error even if I have started the edit operation on workspace?

2

According to the doc, you should have all objects open before you start editing.

I don't know if this matters, but you appear to have started an edit session with undo, by calling iwe.startEditing(true). I don't know if this is supported without versioning, which personal geodatabases don't have.

I would try something like the following untested code:

IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
IWorkspace workspace = new Workspace(workspaceFactory.openFromFile(inFGDB, 0));
IFeatureWorkspace ifw = (IFeatureWorkspace) workspace;
IFeatureClass ifetclass =  ifw.openFeatureClass("CPWire");
IWorkspaceEdit iwe = (IWorkspaceEdit)workspace;
iwe.startEditing(false);
iwe.startEditOperation();

   IFeatureCursor ifc = ifetclass.search(null, true);
   int field = ifc.findField("CREATIONUSER");
   System.out.println("CREATIONUSER :"+field);
   IFeature iff = ifc.nextFeature();
   while((iff = ifc.nextFeature()) != null)
   {
       iff.setValue(field, "xyz");
       iff.store();
   }
iwe.stopEditOperation();
iwe.stopEditing(true);    

If you are actually updating all the rows to a constant value, you could use UpdateSearchedRows to get better performance.

IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
IWorkspace workspace = new Workspace(workspaceFactory.openFromFile(inFGDB, 0));
IFeatureWorkspace ifw = (IFeatureWorkspace) workspace;
IFeatureClass ifetclass =  ifw.openFeatureClass("CPWire");
IWorkspaceEdit iwe = (IWorkspaceEdit)workspace;
iwe.startEditing(false);
iwe.startEditOperation();

   int field = ifc.findField("CREATIONUSER");
   System.out.println("CREATIONUSER :"+field);
   IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
   featureBuffer.set_Value(field, "xyz");

   ITable table = (ITable)featureClass;
   IRowBuffer rowBuffer = (IRowBuffer)featureBuffer;
   table.UpdateSearchedRows(queryFilter, rowBuffer);

iwe.stopEditOperation();
iwe.stopEditing(true); 

For all the different ways to update a feature, there is the Updating features help page.

  • NIce answer , i will try and get back to you/// – NewBee Jul 15 '13 at 3:59
  • NO getting same error for first methord and for second error comes as "Error: com.esri.arcgis.geodatabase.IFeatureClassProxy cannot be cast to com.esri.arcgis.geodatabase.ITable" for the following line "ITable table = (ITable)featureClass; ". – NewBee Jul 15 '13 at 4:24
  • 1
    This is java isn't it...the links I sent, and the majority of my experience, is with .Net. It looks like there is a slightly different pattern when using ArcObjects with java. As in, you are dealing directly with objects, rather then COM interfaces. Maybe this sample will help: help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/… – travis Jul 15 '13 at 6:18
  • I would take a look at this article. It seems to indicate that you should be using the EngineEditor class to start your edit session. resources.arcgis.com/en/help/arcobjects-java/concepts/engine/… – travis Jul 15 '13 at 6:47
2

If you're working on an arcgis engine app then check your licence initializer

change bindingarcgisruntime method the below code

 void BindingArcGISRuntime(object sender, EventArgs e)
    {
        //
        // TODO: Modify ArcGIS runtime binding code as needed
        //            
        if (!RuntimeManager.Bind(ProductCode.Engine))
        {
            // Failed to bind, announce and force exit
            System.Windows.Forms.MessageBox.Show("Invalid ArcGIS runtime binding. Application will shut down.");
            System.Environment.Exit(0);
        }            
        if (ESRI.ArcGIS.RuntimeManager.ActiveRuntime == null)
            ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
        AoInitialize init = new AoInitialize();
        // initialize an ArcGIS Server license if the license is available
        if (init.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeStandard) == esriLicenseStatus.esriLicenseAvailable)
        {
            init.Initialize(esriLicenseProductCode.esriLicenseProductCodeStandard);
            init.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
            init.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
            init.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
            init.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
            init.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
        }
        // throw an exception if the license is not available
        else
            throw new Exception("ESRI ArcGIS Server License is unavailable or has failed");
    }
1

Don't know if this is really the issue here, but based on your sample code you're using an "AccessWorkspaceFactory" which is for Personal GeoDatabases, but (by the name of the variable at least) you are pointing to a FileGeodatabase.

  • My bad that was just a coincidence , i have some filter so that only personal geodatabase can be provided , thats why didnt change the name of variable here //// – NewBee Jul 15 '13 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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