NME: JNI call to generic typed method - a String to Object casting issue?

568 views
Skip to first unread message

Rocks Wang

unread,
Dec 7, 2012, 1:15:51 AM12/7/12
to haxe...@googlegroups.com
Hi all,
 
I know it should not be a problem since generic in java is just a compile-time stuff, after the type erasing, all generic types are replaced by Ljava/lang/Object;.
However when I was trying to invoke such a method with String argument from haXe, I got following error:
E/NME     (19206): HaxeToJNI : jniObject not an object 0x47b697dc
E/NME     (19206): HaxeToJNI could not convert param 0 (0x47b697dc) to 3x0
E/NME     (19206): CallMember - bad argument list
 
my haxe code:
    var Map_new = JNI.createStaticMethod("java/util/HashMap", "<init>", "()V") ;
    var Map_put = JNI.createMemberMethod("java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;") ;
    var Map_size = JNI.createMemberMethod("java/util/Map", "size", "()I") ;
    var map = Map_new();
    trace("tojavamap newinst ok: size=" + Map_size(map)); // this is ok, output is zero
    Map_put(map, "key", "value"); // exception here
 
I'm not familiar with JNI, maybe it's because haxe JNI didn't treat haxe String as a jniObject?

Regards,
Rocks

Hugh

unread,
Dec 10, 2012, 12:51:11 AM12/10/12
to haxe...@googlegroups.com
Hi,
You are right - it should allow you to pass a string to a java.lang.Object.
The fix should be relatively easy to fix in JNI.cpp, before "ELOG("HaxeToJNI : jniObject not an object %p", inValue);"
try (untested):

// Might be a string object...
if (val_is_string(inValue))
{
    out.l = inEnv->NewStringUTF(val_string(inValue));
    return true;
}
// Nope - must be an error...
ELOG("HaxeToJNI : jniObject not an object %p", inValue);


Hugh
Reply all
Reply to author
Forward
0 new messages