记一次linux部署海康sdk错误
报错内容如下
Caused by:
java.lang.Error:
Structure.getFieldOrder() on class com.xxx.sdk.HCNetSDK$NET_DVR_DEVICEINFO_V30 does not provide enough names [0] ([]) to match declared fields [31] ([byAlarmInPortNum, byAlarmOutPortNum, byAudioChanNum, byChanNum, byDVRType, byDiskNum, byHighDChanNum, byIPChanNum, byLanguageType, byMainProto, byMirrorChanNum, byMultiStreamProto, byRes2, byStartChan, byStartDChan, byStartDTalkChan, byStartVoiceInChanNo, bySubProto, bySupport, bySupport1, bySupport2, bySupport3, bySupport4, bySupport5, bySupport6, bySupport7, byVoiceInChanNum, byZeroChanNum, sSerialNumber, wDevType, wStartMirrorChanNo])
错误原因:
这个问题是因为海康jna.jar比较老,结构体定义没有getFiledOrder,可创建一个类继承 Structure
解决方法:
import com.sun.jna.Structure;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;public class HIKSDKStructure extends Structure {protected List<String> getFieldOrder(){List<String> fieldOrderList = new ArrayList<String>();for (Class<?> cls = getClass();!cls.equals(HIKSDKStructure.class);cls = cls.getSuperclass()) {Field[] fields = cls.getDeclaredFields();int modifiers;for (Field field : fields) {modifiers = field.getModifiers();if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {continue;}fieldOrderList.add(field.getName());}}return fieldOrderList;}
}
错误二:
报错内容:
Error creating bean with name 'xxxImpl':
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Invalid calling convention 63
可能错误原因:
海康sdk方法继承了StdCallLibrary.StdCallCallback,它是win32系统使用的
解决方法:
StdCallLibrary.StdCallCallback改成Library, Callback
参考文章