gpt4 book ai didi

java - Delphi 中通过 Java Bridge 使用 DocumentBuilderFactory 时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:43:45 25 4
gpt4 key购买 nike

我正在尝试通过 JNI/Java 桥在 Delphi 代码中使用 javax.xml.parsers.DocumentBuilderFactory。

这是我为工厂构建的接口(interface):

Note: I know in the class the actual creation method is newInstance() but when I try using newInstance instead of init I also get the same segmentation fault.

{DocumentBuilderFactory}
JDocumentBuilderFactoryClass = interface(JObjectClass)
['{8475A5A9-F10A-4DDA-9D50-C714C015C81C}']
function init: JDocumentBuilderFactory; cdecl; overload;
end;

[JavaSignature('javax/xml/parsers/DocumentBuilderFactory')]
JDocumentBuilderFactory = interface(JObject)
['{7F4F2927-25EB-4B03-9373-A43B0757CD06}']
function newDocumentBuilder: JDocumentBuilder; cdecl;
end;

TJDocumentBuilderFactory = class
(TJavaGenericImport<JDocumentBuilderFactoryClass, JDocumentBuilderFactory>)
end;

这是调用接口(interface)/对象的代码:
tmpObject: JObject;

// init an object, i have already tried just calling create
tmpObject := TJDocumentBuilderFactory.JavaClass.init;
//then wrap it into the appropriate object
if Assigned(tmpObject) then
builderFactory := TJDocumentBuilderFactory.Wrap
((tmpObject as IlocalObject).GetObjectID);

据我所知,我不必在接口(interface)中声明java类的每个方法,我使用其他类没有问题。

通常,java 桥引发的段错误表明加载接口(interface)或文件时出现问题。例如,如果 java 签名中 java 类的路径错误,那么也会导致段错误。然而,这里的情况并非如此,因为我可以确认路径是正确的。我环顾四周,但找不到任何有关如何解决此问题的建议。有什么想法吗?

问候,
杰森

最佳答案

段错误是可以理解的,因为不可能创建抽象类的实例。

Android documentation说 DocumentBuilderFactory 是一个抽象类。该类提供了一个静态方法,newDocumentBuilder() ,它返回 DocumentBuilder 的新实例。

要创建工厂实例,请使用 DocumentBuilderFactory。 newInstance ()。

<小时/>

由于我不使用 Delphi 的移动版本,因此我无法说明如何通过 JNI 适配器使用静态工厂方法。如果没有记录,也许值得在 Stackoverflow 上提出自己的问题。

关于java - Delphi 中通过 Java Bridge 使用 DocumentBuilderFactory 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24677545/

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