Hi,
until your JNI code is working, I suggest to have one JNI call per line only
and always check the results. This will imediately tell you where the error
occurred, e.g. if it was jclass == NULL or jobject == NULL and so on. You
can combine it later, once you know your code is working. Also the stack
trace in the android log is more helpful then. Its also better readable.
Plus in your for() - loop, you save the call to “GetObjectClass”, because
that can be done outside the loop.
As for your real problem, I don’t really have a clue. Some answers at SO
(like http://stackoverflow.com/questions/2228275/java-generics-and-jni) seem
to explain a little more, but I have not fully understood it yet.
My best guess is that you can’t ask for the class type you exect here:
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, services), “get”,
"(I)Landroid/bluetooth/BluetoothGattService;");
but that you have to ask for Object instead:
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, services), “get”,
"(I)Ljava/lang/Object;");
The object that you will receive after “CallObjectMethod” should still be of
class android.bluetooth.BluetoothGattService.
Let me know if that works, I’m curious because it’s just a guess.
Regards,
Daniel
---------- P?vodn? zpr?va ----------
Od: ancientcc
Komu: ‘SDL Development List’
Datum: 18. 4. 2016 1:58:54
P?edm?t: Re: [SDL] (android)How to Define List<> in JNI
"
Thanks! I have called List.size() successfully. But have new problem, can
not get “get” method of List.
?
Below is Java code of hope.
{
??? List services = gatt.getServices();
??? int count = services.size();
??? for (int i = 0; i < count; i ++) {
??? BluetoothGattService service = services.get(i);
??? }
}
?
The following is corresponding JNI code.
{
??? jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass
(env, gatt), “getServices”, “()Ljava/util/List;”);
??? jobject services = (*env)->CallObjectMethod(env, gatt, mid);
??? mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env,
services), “size”, “()I”);
??? int count = (*env)->CallIntMethod(env, services, mid);
??? int at;
??? for (at = 0; at < count; at ++) {
??? mid = (*env)->GetMethodID(env, (*env)->
GetObjectClass(env, services), “get”, “(I)Landroid/bluetooth/
BluetoothGattService;”);
??? // Q: the got mid is null!
??? }
}
Q: In the code motion, how to get “get” method of List?
?
On the other hand, why I use jclass to 2nd argument when declaration Java_
org_libsdl_app_xxx? Because SDL code is so used, for example native
functions in src/core/android/SDL_android.c._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"