On Aug 13, 2012, at 7:40 AM, blorecrafter <blorecraf...@gmail.com> wrote:
> I'm able to instantiate the class by the following statements:
> 
> Java.Lang.Object jclassWrp_;
> IntPtr JavaScriptInterface_Class = 
> JNIEnv.FindClass("mypackage.JavaScriptInterface");

JNI use should use JNI conventions, thus "mypackage/JavaScriptInterface" (note 
'/' instead of '.').

> IntPtr JavaScriptInterface_ctor = 
> JNIEnv.GetMethodID(JavaScriptInterface_Class, "<init>", "()V");
> IntPtr jsInterfaceinstance_ = JNIEnv.NewObject(JavaScriptInterface_Class, 
> JavaScriptInterface_ctor);
> jclassWrp_ = new Java.Lang.Object(jsInterfaceinstance_, 
> JniHandleOwnership.TransferGlobalRef);

JNIEnv.NewObject() returns a local ref, not a global ref, so you want 
JniHandleOwnership.TransferLocalRef.

> But when i try to create the object to access the getSelctd() method:
> 
> IntPtr ipApid = JNIEnv.GetMethodID(jclassWrp_, "getSelctd", 
> "()Ljava/lang/String;");

JNIEnv.GetMethodID() takes a class handle, not an instance. Firstly, the above 
shouldn't compile (Java.Lang.Object != IntPtr). Secondly, jclassWrp contains a 
mypackage.JavaScriptInterface instance, not the mypackage.JavaScriptInterface 
Class.

Instead, do:

        IntPtr ipApid = JNIEnv.GetMethodID(JavaScriptInterface_Class, 
"getSelctd", "()Ljava/lang/String;");

Finally, don't forget to JNIEnv.DeleteGlobalRef(JavaScriptInterface_Class) when 
you don't need it anymore, otherwise you'll leak the gref.

 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to