1

Following my previous question (Why I receive Invoke error: method not found), I found a problem and want to make it as a new standalone question.

I have this class in Java:

public class myClass {

  public static void init(String key, Context context) {}

}

And I have this code in Delphi:

type
  JMyClassClass = interface(JObjectClass)
    ['{2E91BB84-D9C9-4569-A687-BCB3684A8DBD}']
    {class} procedure init(key: JString; context: JContext); cdecl;
  end;

  [JavaSignature('com/myClass')]
  JMyClass = interface(JObject)
    ['{2761621D-63E1-4F57-964D-46FBE81DAB8B}']
  end;
  TJMyClass = class(TJavaGenericImport<JMyClassClass, JMyClass>) end;

When I do this in Delphi:

TJMyClass.JavaClass.init(StringToJstring('toto'), TAndroidHelper.Context.getApplicationContext);

I will receive this error:

Invoke error: method not found

if I rename init to anything else (like initialize, for example), it will work! But as it's not my library, I can not rename the function.

How can I call the init function from Delphi?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
zeus
  • 12,173
  • 9
  • 63
  • 184
  • Embarcadero's JNIBridge framework uses its own `init()` methods for class constructors. If a class has an actual non-constructor `init()` method, there is likely a conflict within the framework's internal logic. You should [file a bug report](https://quality.embarcadero.com) with Embarcadero. – Remy Lebeau Nov 04 '18 at 17:04
  • Can you not declare a descendant in Java code? I'm guessing you'd rather avoid that – Dave Nottage Nov 04 '18 at 22:59
  • @DaveNottage : yes it's what i did, ut it's a pity to create a new jar that wrap another jar just because it's impossible to bind in delphi a function named "init" :( – zeus Nov 05 '18 at 05:31
  • @RemyLebeau It's already reported, here: https://quality.embarcadero.com/browse/RSP-10150 – Dave Nottage Sep 16 '19 at 21:33

0 Answers0