linux  arcengine for java   openFeatureClass(Unknown Source)

483
2
03-25-2011 07:51 PM
zhuxiaochen
New Contributor
I use arcengine for java in linux operation.
The exception I got was "AutomationException: 0x80004005 - Unspecified error".
My product version is arcengine 9.3 java for linux.
error in
at com.esri.arcgis.geodatabase.Workspace.openFeatureClass(Unknown Source)

code
{
String workspacePath = arcGISHome + "/java/samples/data/usa";
String featureClassName = "states.shp";
File shapefileFile = new File(workspacePath, featureClassName);
if (!shapefileFile.exists()) {
System.out.println("Shapefile " + shapefileFile.getAbsolutePath() + " doesn't exist. Exiting.");
System.exit(-1);
}
System.out.println("Shapefile: " + shapefileFile.getAbsolutePath());

try {
AoInitialize aoInitializer = new AoInitialize();
aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

ShapefileWorkspaceFactory shapefileWorkspaceFactory = new ShapefileWorkspaceFactory();
Workspace workspace = new Workspace(shapefileWorkspaceFactory.openFromFile(workspacePath, 0));
FeatureClass featureClass = new FeatureClass(workspace.openFeatureClass(featureClassName)); int numFeatures = featureClass.featureCount(null);
System.out.println("There are " + numFeatures + " features:");

for (int i = 0; i < numFeatures; i++){
IFeature feature = featureClass.getFeature(i);
IGeometry geometry = feature.getShapeCopy();
System.out.println("Feature " + i + ": ");
System.out.println(getStringFromShape(geometry));
if (i >= 9) {
break; // 10 is enough
}
}
aoInitializer.shutdown();
System.out.println("Sample finished.");
} catch (Exception e) {
e.printStackTrace();
}

}


why use workspace.openFeatureClass in some errors,the shapefile's path and name is correct .

Any solution or workaround this?

Thank you very much in advance
0 Kudos
2 Replies
EricBader
Occasional Contributor III
Hello!

Do you call EngineInitializer.initializeEngine() anywhere? You need to call this before you do AoInitialize.
0 Kudos
zhuxiaochen
New Contributor
Hello! 

Do you call EngineInitializer.initializeEngine() anywhere? You need to call this before you do AoInitialize.


Thanks very much!
I add EngineInitializer.initializeEngine() into the front of AoInitialize ,
but the same error.


code :

String workspacePath = arcGISHome + "/java/samples/data/usa";
String featureClassName = "states.shp";
File shapefileFile = new File(workspacePath, featureClassName);
if (!shapefileFile.exists()) {
System.out.println("Shapefile " + shapefileFile.getAbsolutePath() + " doesn't exist. Exiting.");
System.exit(-1);
}
System.out.println("Shapefile: " + shapefileFile.getAbsolutePath());

try {
EngineInitializer.initializeEngine() ;
AoInitialize aoInitializer = new AoInitialize();
aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

ShapefileWorkspaceFactory shapefileWorkspaceFactory = new ShapefileWorkspaceFactory();
Workspace workspace = new Workspace(shapefileWorkspaceFactory.openFromFile(workspacePath, 0));
FeatureClass featureClass = new FeatureClass(workspace.openFeatureClass(featureClassName));
int numFeatures = featureClass.featureCount(null);
System.out.println("There are " + numFeatures + " features:");

for (int i = 0; i < numFeatures; i++){
IFeature feature = featureClass.getFeature(i);
IGeometry geometry = feature.getShapeCopy();
System.out.println("Feature " + i + ": ");
System.out.println(getStringFromShape(geometry));
if (i >= 9) {
break; // 10 is enough
}
}
aoInitializer.shutdown();
System.out.println("Sample finished.");
} catch (Exception e) {
e.printStackTrace();
}


error:
"AutomationException: 0x80004005 - Unspecified error".
at com.esri.arcgis.geodatabase.Workspace.openFeatureClass(Unknown Source)
0 Kudos