Calling from C++ Java method which returns List<int[]>
-
Hi,
I'm trying to call getSupportedPreviewFpsRange Java method from C++. This method has signature
List<int[]> getSupportedPreviewFpsRange ()
so first I do:QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange", "()Ljava/util/List;");
which returns valid object. Then I try to call
get
method to accessjintArray
(?).Got undefined reference error:
rangeListNative.callMethod<jintArray>("get", "(I)[I", i);
Method not found error:
rangeListNative.callObjectMethod<jintArray>("get", "(I)[I", i);
Returns null pointer:
rangeListNative.callObjectMethod("get", "(I)[I", i);
What is the right way to do it?
-
I have a similar method signature that I use for Android. I have no idea if this will be beneficial for you or not...
Possibly replace "(I)Ljava/lang/Object" with "(I)Ljava/lang/List"QAndroidJniObject jResult =resultsVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
-
I have a similar method signature that I use for Android. I have no idea if this will be beneficial for you or not...
Possibly replace "(I)Ljava/lang/Object" with "(I)Ljava/lang/List"QAndroidJniObject jResult =resultsVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
@Carmoneer but how can I get value for jintArray from it? is it a correct way:
QJNIObjectPrivate jRange =resultsVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i); jintArray jRange = static_cast<jintArray>(range.object());
?
-
Actually it works :) Here is a full code snippet:
QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange", "()Ljava/util/List;"); int count = rangeListNative.callMethod<jint>("size"); for (int i = 0; i < count; ++i) { QJNIObjectPrivate range = rangeListNative.callObjectMethod("get", "(I)Ljava/lang/Object;", i); jintArray jRange = static_cast<jintArray>(range.object()); jint* rangeArray = env->GetIntArrayElements(jRange, 0); AndroidCamera::FpsRange fpsRange; /* int */ fpsRange.min = rangeArray[0]; /* int */ fpsRange.max = rangeArray[1]; env->ReleaseIntArrayElements(jRange, rangeArray, 0); rangeList << fpsRange; }
wonder if it's correct (?).
-
Actually it works :) Here is a full code snippet:
QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange", "()Ljava/util/List;"); int count = rangeListNative.callMethod<jint>("size"); for (int i = 0; i < count; ++i) { QJNIObjectPrivate range = rangeListNative.callObjectMethod("get", "(I)Ljava/lang/Object;", i); jintArray jRange = static_cast<jintArray>(range.object()); jint* rangeArray = env->GetIntArrayElements(jRange, 0); AndroidCamera::FpsRange fpsRange; /* int */ fpsRange.min = rangeArray[0]; /* int */ fpsRange.max = rangeArray[1]; env->ReleaseIntArrayElements(jRange, rangeArray, 0); rangeList << fpsRange; }
wonder if it's correct (?).
@Ruslan-Baratov said:
wonder if it's correct (?).
I just use the "get" method. Not sure is your method "correct", but it looks fine.
My code:
https://github.com/benlau/quickandroid/blob/master/qasystemdispatcher.cpp#L41 -
@Ruslan-Baratov said:
wonder if it's correct (?).
I just use the "get" method. Not sure is your method "correct", but it looks fine.
My code:
https://github.com/benlau/quickandroid/blob/master/qasystemdispatcher.cpp#L41I just use the "get" method
@benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array
int[]
. -
I just use the "get" method
@benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array
int[]
.@Ruslan-Baratov said:
I just use the "get" method
@benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array
int[]
.Everything in Java is an object. Regardless of the actual storage method , List<T> is in fact an array of java.lang.Object, but you could use it like an
int[]
. -
@Ruslan-Baratov said:
I just use the "get" method
@benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array
int[]
.Everything in Java is an object. Regardless of the actual storage method , List<T> is in fact an array of java.lang.Object, but you could use it like an
int[]
.Everything in Java is an object
@benlau Okay, thanks for the information. Good to know :)