我试图实现一个类似于在FMX.Advertising.Android
.
type
// Forward declaration
JAttentiveListener = interface; //com.pack.AttentiveListener
//...
JAttentiveListenerClass = interface(IJavaClass)
['{28A2CA13-A965-4EAB-A4F0-481E20C9AF2A}']
end;
[JavaSignature('com/pack/AttentiveListener')]
JAttentiveListener = interface(IJavaInstance)
['{45D40262-E5C2-4650-B64A-4C5D56EA6107}']
{Methods}
procedure onClicked; cdecl;
procedure onNotReceived(message1: JString); cdecl;
procedure onReceived; cdecl;
end;
TJAttentiveListener = class(TJavaGenericImport<JAttentiveListenerClass, JAttentiveListener>) end;
TMyListener = class(TJavaLocal, JAttentiveListener) // JAttentiveListener is Android interface imported above using JNI
private
FObj: TCallbackObj;
public
constructor Create(Obj: TCallbackObj);
destructor Destroy; override;
procedure onClicked; cdecl;
procedure onNotReceived(message1: JString); cdecl;
procedure onReceived; cdecl;
end;
{TMyListener}
constructor TMyListener.Create(Obj: TCallbackObj);
begin
inherited Create; // exception here.
FObj := Obj;
end;
构造函数在 UI 线程中调用,并NullPointerException
在调用父构造函数期间抛出。日志中有以下消息:
我尝试一步一步调试,并步入TJavaLocal
's c-tor. 此 c-tor 的以下语句中出现异常:
FLocalRefObjectID := AJNIEnv^.CallObjectMethodA(AJNIEnv, AJNIObject, CreateProxyClass, PJNIValue(ArgsToJNIValues([ClsID, Self])));
HandleJNIException(AJNIEnv); // NullPointerException is here
为什么同样的事情FMX.Advertising.Android
在我的代码中起作用而在我的代码中不起作用?(我正在尝试创建一个侦听器来实现一个接口并执行类似AdsListener
from 的所有操作FMX.Advertising.Android
。)