我正在使用 MATLAB 的 javabuilder 工具在 MATLAB 运行时环境中执行 MATLAB Native Code。
代码
public String getCHINdex(String tsDataJSON){
MWCharArray number1 = null;
Object[] result = null;
Calibration calibration = null;
try
{
number1 = new MWCharArray(tsDataJSON) ; // Array of Input to be sent to MATLAB Runtime
calibration = new Calibration();
result = calibration.calibrationAPI(1, number1);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
MWArray.disposeArray(number1);
MWArray.disposeArray(result);
calibration.dispose();
}
if(result.length >= 1){
return result[0].toString();
}
return null;
}
例外
Exception in thread "main" java.lang.IllegalStateException: Attempt to use an MWArray that has been disposed
at com.mathworks.toolbox.javabuilder.NativeArray.get(NativeArray.java:122)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.mxArrayToString(Native Method)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$1600(MWMCR.java:31)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mxArrayToString(MWMCR.java:949)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(MWMCR.java:769)
at com.sun.proxy.$Proxy0.mxArrayToString(Unknown Source)
at com.mathworks.toolbox.javabuilder.MWBuiltinArray.toString(MWBuiltinArray.java:180)
at com.mathworks.toolbox.javabuilder.MWCharArray.toString(MWCharArray.java:24)
at .CHIndexCalculation.getCHINdex(CHIndexCalculation.java:45)
at .CHIndexCalculation.main(CHIndexCalculation.java:15)
我不确定是什么导致了这个异常?当我第二次运行代码时会发生这种情况。从错误中我可以看出它必须与使用已处置的数组有关。但我不确定为什么会出现这种情况。我每次都创建一个新对象。