Reputation: 13454
I am writing an Android App using XE7. I have a java source file that contains a class that I wish to use. I am struggling with the exact way of creating and working with this class. I have done the following:
The supplied file (a commercial JAVA library) is called FT311I2CInterface.java. (It gives access to the FT311 USB device). The class inside this file is called "FT311I2CInterface".
This file is part of an Android demo project that I was able to compile and run using Eclipse. Further, I was able to generate "FT311I2CInterface.jar" from "FT311I2CInterface.java".
I have added "FT311I2CInterface.jar" under the library node of my Delphi Android project.
From "FT311I2CInterface.jar" I tried to extract a Delphi interface for this class using the recommended Java2op.exe tool but was not successful, but using the commercial tool Java2Pas I did obtain a Delphi interface "JFT311I2CInterfaceClass" and "TJFT311I2CInterface".
Using this interface I have constructed and run a simple Android project that calls this import unit, creates an instance of this class ready for me to call its methods.
My creation line is:
procedure Test;
var
F311 : JFT311I2CInterface;
begin
F311 := TJFT311I2CInterface.JavaClass.init( MainActivity );
// ...
end;
when this line is called, I get the error:
Exception class EJNI with message 'Java class JFT311I2CInterface could not be found'. Process Project1.apk (6287)
My question is, do I have to register or load this class in some way before I can call it? I see that there are lots of examples of calling Java classes from Delphi but I am confused when it comes to using a class that is not already in the Android SDK.
Upvotes: 2
Views: 1018
Reputation: 2287
Look for the video and website's from Brian Long. He has an example of creating a Delphi Android wrapper (for a Java class) that isn't supplied by Embarcadero. His example is for calling Toast. There are lots of gotcha's here, but if you can follow how he "translated" the Android Api documentation into a Delphi wrapper, then you'll be able to do the same for your own Java class - eventually. There are 1 or 2 of my own here on SO. Compare the Android documentation with the Delphi wrapper implementation until you see the pattern emerge.
Upvotes: 1