gpt4 book ai didi

java - JNA getFieldOrder() 导致名称在 HashSet() 比较中不匹配(JNA 的 Structure.java,第 925 行)

转载 作者:搜寻专家 更新时间:2023-11-01 03:05:40 27 4
gpt4 key购买 nike

遇到令人抓狂的阻塞错误:

Exception in thread "main" java.lang.Error: Structure.getFieldOrder() on class com.luke.generator.GeneratorEngine$VERSION_INFO returns names ([BuildString, ProtocolMajorVer, ProtocolMinorVer]) which do not match declared field names ([BiuldString, ProtocolMajorVer, ProtocolMinorVer])

at com.sun.jna.Structure.getFields(Structure.java:925)
at com.sun.jna.Structure.deriveLayout(Structure.java:1058)
at com.sun.jna.Structure.calculateSize(Structure.java:982)
at com.sun.jna.Structure.calculateSize(Structure.java:949)
at com.sun.jna.Structure.allocateMemory(Structure.java:375)
at com.sun.jna.Structure.<init>(Structure.java:184)
at com.sun.jna.Structure.<init>(Structure.java:172)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.Structure.<init>(Structure.java:151)
at com.luke.generator.GeneratorEngine$.<init>(GeneratorEngine.java:108)
at com.luke.generator.connectionVersion(GeneratorEngine.java:297)
at com.luke.generator.Main.main(Main.java:161)

平台:英特尔、Windows 8JRE 1.7,32 位 (x86)Eclipse Kepler,默认编码 UTF-8jna-4.1.0.jar32 位 CPP DLL - 我可以确认我正在加载库并调用不包含参数的函数。我也尝试传递 WString 和字符串,但这并没有解决问题。

来源:

CPP 结构:

typedef struct {
UINT32 ProtocolMajorVer;
UINT32 ProtocolMinorVer;
UI_STRING BuildString; // Build version for the application.
} VERSION_INFO;

CPP函数

DLL_EXPORTS RETURN_TYPES ConnectionVersion (VERSION_INFO    &Version) {<body omitted>}

Java代码:

//Interface definition
public interface UiApi extends StdCallLibrary {

UiApi INSTANCE = (UiApi) Native.loadLibrary(UiApiPath,UiApi.class);

final String PROTOCOLMAJORVERSION = new String("ProtocolMajorVer");
final String PROTOCOLMINORVERSION = new String("ProtocolMinorVer");
final String BUILDSTRING = new String("BuildString");


public static class VERSION_INFO extends Structure {

public static class ByReference extends VERSION_INFO implements Structure.ByReference {}
public static class ByValue extends VERSION_INFO implements Structure.ByValue {}

public int ProtocolMajorVer;
public int ProtocolMinorVer;
public byte[] BiuldString;


protected List getFieldOrder() {
return Arrays.asList(new String[] { "ProtocolMajorVer","ProtocolMinorVer","BuildString" });
}
}

//Connection
public int Connect(byte[] strServerName);
public int Disconnect();
public int CloseProject();

public int ConnectionVersion(VERSION_INFO result);
public int ConnectionVersion(VERSION_INFO.ByReference result);
public int ConnectionVersion(VERSION_INFO.ByValue result);


}

//Engine.connectionVersion() method
public static int connectionVersion() {

int nReturn = 0;
String str = new String("This is my build version\n");

UiApi uiapilib;

uiapilib = UiApi.INSTANCE;

try {

UiApi.VERSION_INFO.ByReference result = new UiApi.VERSION_INFO.ByReference();


result.ProtocolMajorVer = 0;
result.ProtocolMinorVer = 0;
result.BiuldString = str.getBytes();

nReturn = uiapilib.ConnectionVersion(result);
}
catch (Exception e) {
System.out.println("Error=" + e.getLocalizedMessage());

}

return nReturn;

}


//This is the code in main that results in exception


private static Engine engine;

engine = new GeneratorEngine();
engine.connectionVersion();

我一定是遗漏了一些基本的东西。 Eclipse 中是否有可能导致 JNA 的 Structure.java(第 925 行)中的 HashSet 名称比较导致名称不匹配?从抛出的异常来看,这些定义看起来是一样的。

感谢您提供的任何提示、指导和新观点。

最佳答案

检查拼写 - 该字段名为 BiuldString 而不是 BuildString,您将 i 和 u 颠倒了。

关于java - JNA getFieldOrder() 导致名称在 HashSet() 比较中不匹配(JNA 的 Structure.java,第 925 行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23690307/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com