简体   繁体   中英

Segmentation Fault when using DocumentBuilderFactory through the Java Bridge in Delphi

I'm trying to use javax.xml.parsers.DocumentBuilderFactory in Delphi code through the JNI/Java Bridge.

This is the interface I constructed for the factory:

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;

And this is the code calling the interface/object:
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);

As far as I know I don't have to declare every method of the java class in the interface, I have used other classes without problems.

Usually segmentation faults raised by the java bridge indicate that there is a problem loading the interface or file. For example, if the path to the java class in the java signature is wrong then that will result in a segmentation fault too. However this is not the case here since I can confirm that the path is right. I've looked around but I can't find any suggestions as to how to resolve this problem. Any ideas?

regards,
Jason

The segmentation fault is understandable because it is not possible to create instances of abstract classes.

The Android documentation says that DocumentBuilderFactory is an abstract class. The class provides a static method, newDocumentBuilder() , which returns a new instance of a DocumentBuilder.

To create an instance of the factory, use DocumentBuilderFactory. newInstance ().


As I do not work with a mobile edition of Delphi, I can not say how a static factory method can be used over the JNI adapter. If it is not documented, maybe it is worth its own Stackoverflow question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM