I want to use ArcEngine to read some CAD files on the server and I can not shut down the program. Now I meet the problem that when I open a FeatureClass of CAD file on the second time, A fatal error has been detected by the Java Runtime Environment:EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x5653d153, pid=4164, tid=7888. The code looks like below:
Here is the main method:
public static void main(String[] args){
for(int i=0;i<2;i++){
System.out.println("////////////////////"+i+"/////////////////");
try {
OpenCadMgr openCadMgr0 = new OpenCadMgr("0.dwg");
openCadMgr0.showTexts();
OpenCadMgr openCadMgr1 = new OpenCadMgr("1.dwg");
openCadMgr1.showTexts();
OpenCadMgr openCadMgr2 = new OpenCadMgr("2.dwg");
openCadMgr2.showTexts();
OpenCadMgr openCadMgr3 = new OpenCadMgr("3.dwg");
openCadMgr3.showTexts();
OpenCadMgr openCadMgr4 = new OpenCadMgr("4.dwg");
openCadMgr4.showTexts();
OpenCadMgr openCadMgr5 = new OpenCadMgr("5.dwg");
openCadMgr5.showTexts();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("end");
}
the OpenCadMgr code is below:
public class OpenCadMgr {
CADLayerCreator _cadLyrCreator;
String nameOfCadFile = "";
public OpenCadMgr(String fileName) throws Exception, IOException {
nameOfCadFileString = fileName;
String nameOfPathString = "C:\\Users\\test\\Documents\\code\\data";
this._cadLyrCreator = new CADLayerCreator(nameOfPathString, fileName);
nameOfCadFile = fileName;
initLicence();
}
private void initLicence() {}
public void showTexts() {
try {
IFeatureClass pTxtFeatureClass = this._cadLyrCreator.getCadFC(FeatureType.multitext);
if (pTxtFeatureClass != null) {
IFeatureCursor pFeatureCursor = pTxtFeatureClass.search(null, false);
IFeature pFeature = pFeatureCursor.nextFeature();
int featureIndex = 0;
while (pFeature != null) {
int index = pFeature.getFields().findField("text");
String txtString = pFeature.getValue(index).toString();
IPoint ptIPoint = (IPoint) pFeature.getShape();
pFeature = pFeatureCursor.nextFeature();
featureIndex++;
}
System.out.println(nameOfCadFile);
Cleaner.release(pFeatureCursor);
Cleaner.release(pFeature);
}
Cleaner.release(pTxtFeatureClass);
this._cadLyrCreator.disposeAO();
} catch (Exception e) {
e.printStackTrace();
}
}
}
The CADLayerCreator class code is here:
public class CADLayerCreator { private static HashMap<String,IFeatureClass> fDict = new HashMap<String, IFeatureClass>(); private String _nameOfPath;// the path of CAD file private String _nameOfCADFile;// the name of CAD file IWorkspaceFactory pWorkspaceFactory; IWorkspace pWorkspace; IFeatureWorkspace pFeatureWorkspace; IFeatureClass pFeatureClass; public CADLayerCreator(String nameOfPath, String nameOfCADFile) { this._nameOfPath = nameOfPath; this._nameOfCADFile = nameOfCADFile; } public IFeatureClass getCadFC(FeatureType FT) throws Exception{ try { if (!this.isFileExist()) { throw new IOException(String.format("can not find the file named '%s' in the path of '%s'!", this._nameOfPath, this._nameOfCADFile)); } // get cad file full name String openString = getCadFullNameString(FT); // set the workspace factory pWorkspaceFactory = new CadWorkspaceFactory(); // open the workspace pWorkspace = pWorkspaceFactory.openFromFile(this._nameOfPath, 0); pFeatureWorkspace = new IFeatureWorkspaceProxy(pWorkspace); pFeatureClass = pFeatureWorkspace.openFeatureClass(openString); fDict.put(openString,pFeatureClass); return pFeatureClass; } catch (Exception e) { throw new Exception("CADLayerCreator-> GetCadFC-> " + e.getMessage()); } } public void disposeAO(){ pWorkspaceFactory = null; pWorkspace = null; pFeatureWorkspace = null; pFeatureClass = null; // Cleaner.release(pWorkspaceFactory); // Cleaner.release(pWorkspace); // Cleaner.release(pFeatureWorkspace); // Cleaner.release(pFeatureClass); System.gc(); } private IFeatureWorkspace getFW(String name) throws Exception { try { // set the workspace factory IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactory(); // open the workspace IWorkspace pWorkspace = pWorkspaceFactory.openFromFile(name, 0); // set the feature workspace IFeatureWorkspace pFeatureWorkspace = new IFeatureWorkspaceProxy(pWorkspace); return pFeatureWorkspace; } catch (Exception e) { // TODO: handle exception throw new Exception("CADLayerCreator-> getFW-> " + e.getMessage()); } } private boolean isFileExist() { String fullPath = this._nameOfPath + "\\" + this._nameOfCADFile; File file = new File(fullPath); return file.exists(); } private String getCadFullNameString(FeatureType pFT) throws Exception { try { switch (pFT) { case polyline: return this._nameOfCADFile + ":Polyline"; case multitext: return this._nameOfCADFile + ":Annotation"; default: return this._nameOfCADFile + ":Polyline"; } } catch (Exception e) { throw new Exception("CADLayerCreator -> getCadFullNameString -> " + e.getMessage()); } }
}
Here is the console log:
////////////////////////////////////////0///////////////////////////////////
0.dwg
1.dwg
2.dwg
3.dwg
4.dwg
5.dwg
////////////////////////////////////////1///////////////////////////////////
0.dwg//the 0.dwg file can be read again,but the 1.dwg file can't
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x5653d153, pid=4164, tid=7888
#
# JRE version: Java(TM) SE Runtime Environment (7.0_79-b15) (build 1.7.0_79-b15)
# Java VM: Java HotSpot(TM) Client VM (24.79-b02 mixed mode windows-x86 )
# Problematic frame:
# C 0x5653d153
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\test\Documents\CadReader\hs_err_pid4164.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
I'm not sure whether it is the reason of ArcEngine cannot release the featureclass which I have created or the CAD files have some errors?Can anyone help?