Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: "Java class JMethods could not be found" exception calling JAR library


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Jan 28, 2016 2:11 AM Last Post By: Dennies Chang
Brian Frost

Posts: 3
Registered: 12/21/06
"Java class JMethods could not be found" exception calling JAR library  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2014 3:53 AM
I am trying to use a commercial java library (in a JAR file) and I am having difficulty getting started with the calls from Delphi XE7. So, I've made a simple java JAR file containing a very simple class 'Methods'. Using 'JavaToPas' I've generated a bridge unit as shown below. I've then placed my JAR file as a library under my Android project, and I can see it in my deployment list, targeting ".\assets\internal"

To instantiate this class I do:

=======================
var
Obj : JObject;
begin
Obj := TJMethods.JavaClass.init;
=======================

but I get "Java class JMethods could not be found". It appears to me that the Delphi documentation implies that simply adding my 'test.jar' file to my project is all I need to do to include the classes (rather than get into classes.dex?) but am I missing some additional class registration or similar?

Thanks for any help.


=====================================
unit Methods;

interface

uses
AndroidAPI.JNIBridge,
Androidapi.JNI.JavaTypes;

type
JMethods = interface;

JMethodsClass = interface(JObjectClass)
['{B8811336-4CE2-4FD3-9E37-C7774431CA74}']
procedure main(TJavaArrayJStringparam0 : TJavaArray<JString>) ; cdecl; // ([Ljava/lang/String;)V A: $9
end;

[JavaSignature('Methods')]
JMethods = interface(JObject)
['{3C13392B-C7CF-4F3B-8141-2BEA8C04F6E6}']
end;

TJMethods = class(TJavaGenericImport<JMethodsClass, JMethods>)
end;

implementation

end.
=============================

Eli M

Posts: 1,346
Registered: 11/9/13
Re: "Java class JMethods could not be found" exception calling JAR library  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2014 7:11 AM   in response to: Brian Frost in response to: Brian Frost
Make sure there is only one classes.dex defined in your deployment. Other people where they couldn't see the Java functions had 2 classes.dex files defined so it wasn't using the new one w/ the JAR info.

There is also this tool (Embarcadero's version of Java2pas):
http://docwiki.embarcadero.com/RADStudio/XE7/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android
Brian Frost

Posts: 3
Registered: 12/21/06
Re: "Java class JMethods could not be found" exception calling JAR library  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2014 7:48 AM   in response to: Eli M in response to: Eli M
Eli M wrote:
Make sure there is only one classes.dex defined in your deployment. Other people where they couldn't see the Java functions had 2 classes.dex files defined so it wasn't using the new one w/ the JAR info.

There is also this tool (Embarcadero's version of Java2pas):
http://docwiki.embarcadero.com/RADStudio/XE7/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android

Thanks Eli M, there were indeed two classes.dex listed in the deployment list, one in the Delphi XE7 tree and the other in my folders. I unticked the former and now the 'class not found' error has gone, but I get a segmentation fault from the instantiation of the class. How do I create my class from its DEX? Do I have to do more that just call init on the JavaClass of my bridge definitions?
Thanks
Brian.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: "Java class JMethods could not be found" exception calling JAR library  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2014 8:21 AM   in response to: Brian Frost in response to: Brian Frost
Here are two samples of JAR library integrations. Maybe they have code that will help.

http://bluexmas.tistory.com/427
http://brsatalay.blogspot.com.tr/2014/11/delphi-android-adbuddiz-reklam-ag.html
Brian Frost

Posts: 3
Registered: 12/21/06
Re: "Java class JMethods could not be found" exception calling JAR library  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 3, 2014 11:44 AM   in response to: Eli M in response to: Eli M
Eli M wrote:
Here are two samples of JAR library integrations. Maybe they have code that will help.

http://bluexmas.tistory.com/427
http://brsatalay.blogspot.com.tr/2014/11/delphi-android-adbuddiz-reklam-ag.html

Thanks Eli M, much appreciated.
Regards, Brian.
Dennies Chang

Posts: 1
Registered: 9/22/13
Re: "Java class JMethods could not be found" exception calling JAR library  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2016 2:11 AM   in response to: Brian Frost in response to: Brian Frost
Brian Frost wrote:
Eli M wrote:
Make sure there is only one classes.dex defined in your deployment. Other people where they couldn't see the Java functions had 2 classes.dex files defined so it wasn't using the new one w/ the JAR info.

There is also this tool (Embarcadero's version of Java2pas):
http://docwiki.embarcadero.com/RADStudio/XE7/en/Java2OP.exe,_the_Native_Bridge_File_Generator_for_Android

Thanks Eli M, there were indeed two classes.dex listed in the deployment list, one in the Delphi XE7 tree and the other in my folders. I unticked the former and now the 'class not found' error has gone, but I get a segmentation fault from the instantiation of the class. How do I create my class from its DEX? Do I have to do more that just call init on the JavaClass of my bridge definitions?
Thanks
Brian.

I have the exactly the same status as Brian.

My project requires integrated Alipay SDK, there are 2 parts about this SDK,
one for iOS (it's done), and the other is for Android.

I had added JAR file provided by SDK package, and create classes.dex, make sure
the created copy is assigned as deployment target.

Without this step (classes.dex assignment), the project reports "Class not found", and
after classes.dex is assigned, the class is able to be located, but when I tried to initialize
the class, project report "Segmentation Fault (11)" all the time.

Would you please provide any idea about this? Thanks in advance.

Best Regard,
Dennies.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02