Use JNI to Create, Populate and Return a Java Class Instance

后端 未结 2 538
南笙
南笙 2020-12-14 11:24

I\'m trying to use a JNI function to create a Java class and set some properties of that class using the DeviceId.java constructor method. I\'m able to get the constructor

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 12:02

    When you called GetMethodID, you provided the signature for the two-arg constructor. Thus, you just need to pass your jstring and a jbytearray when you call NewObject - for example:

    return (*env)->NewObject(env, c, cnstrctr, id, cache);
    

    You don't need to call the setId and setCache methods unless you decide to call the 0-arg constructor - and that just complicates your code since you'll have to call GetMethodID for those and call them. Simpler to continue down the route you're on.

提交回复
热议问题