I'm programming with the ARCGIS Java SDK, in Eclipse.

I need to cast an IFeatureClass to an ISchemalock. This cast is supposed to be allowed. There is an example of this cast in: http://resources.esri.com/help/9.3/arcgisengine/java/doc/b22267cb-642c-11dc-9ca3-0b35f906bb2e.htm

However, when I try to perform this cast in my code, an exception appears:

Exception in thread "main" java.lang.ClassCastException: com.esri.arcgis.geodatabase.IFeatureClassProxy cannot be cast to com.esri.arcgis.geodatabase.ISchemaLock

Are you able to make this cast on an IFeatureClass ? Here is the code to perform this:

//Attempt to acquire an exclusive schema lock on the feature class.
IFeatureClass fc = fw.openFeatureClass("featureclass name");
ISchemaLock schemaLock = (ISchemaLock)fc ;

I would appreciate if you could try this simple line of code in one of your programs.

Keep me posted...

EDIT: I wanted to see if an IFeatureClass was, at least, recognized as an instance of ISchemaLock. Believe it or not, it was NOT recognized as an ISchemaLock! The execution of the code below did not enter the if statement.

if (fc instanceof ISchemaLock) 
  System.out.println("all ok");
  ISchemaLock schemaLock = (ISchemaLock)fc;

Maybe is there something not correctly installed with Eclipse ?


I tried a workaround to my casting problem: I first cast my IFeatureClass object into a FeatureClass object, then I cast this FeatureClass into an ISchemaLock.

IFeatureClass --cast--> FeatureClass --cast--> ISchemaLock

The code looks like this:

// Attemp to convert an IFeatureClass into an ISchemaLock
// and then change the SchemaLock
IFeatureClass fc = fw.openFeatureClass("featureclass name");
FeatureClass ffc = new FeatureClass(fc)
ISchemaLock schemaLock = (ISchemaLock)ffc;

I'm able to run this code without exceptions. However, I'm really not convinced that it works properly, because when I try to add an index to my FeatureClass, errors are displayed at the screen (when I run this line of code).


To summarize, I'm not sure that the "workaround" I used for casting an IFeatureClass to a ISchemalock is correct. This workaround for casting doesnt show errors, but the next commands (adding an index to the featureclass) send an error.[Notice that adding an index to a feature class requires a change in the schemalock of this featureclass]

  • Yes, this is more along the lines of what I was thinking, odd that it still doesn't allow you to add an index. Any helpful information in the error that is returned? – Daniel R Apr 25 '13 at 15:16
  • Dear Daniel, maybe the EDIT in the original post could give you some ideas ? – user2309238 Apr 27 '13 at 2:00

This type of call works for me in a number of C# applications, but afraid I don't have a Java environment to work with. From the error, it sounds like the object you have may not support casting in this way. The following article maybe helpful Casting and Runtime type checking. If that is the case, you can try something like

IFeatureClass fc = fw.openFeatureClass("featureclass name");
FeatureClass featureClass = new FeatureClass(fc);
ISchemaLock lock = (ISchemaLock)featureClass;
  • Dear Daniel, unfortunately the code line that you proposed is not valid. The class "ISchemaLock" is not an instantiable class, thus, the sentence: new ISchemaLock(fc); provides an error. – user2309238 Apr 25 '13 at 13:04
  • Dear Daniel, the updated lines of code that you propose here (i.e., in your edited answer) works well, without error messages. – user2309238 Apr 25 '13 at 16:15

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.