I have a C ++ class called androidGPS with public methods and variables. Inside this class, I use JNI to invoke some Java code. But I am stuck in registerNatives function.
My C ++ class has this void method:
void LocationChanged(JNIEnv* env, jobject object, jstring paramsString);
Implemented as follows:
void androidGPS::LocationChanged(JNIEnv*, jobject, jstring paramsString)
{
const char * nativeString = currEnv->GetStringUTFChars(paramsString, 0);
QString qstring(nativeString);
QStringList res;
res << qstring;
emit newReadAvailable(res);
}
The Java class I'm trying to bind has the following method:
public static native void sndonLocationChanged(String currLocation);
I declare JNINativeMethods as a local variable before calling native registers like:
JNINativeMethod methods[] =
{
{
"sndonLocationChanged",
"(Ljava/lang/String;)V",
(void *)&androidGPS::LocationChanged
}
};
Call subscriber registers:
int numMethods;
numMethods = sizeof(methods) / sizeof(methods[0]);
if (currEnv->RegisterNatives(listenerClass, methods, numMethods) < 0)
{
if (currEnv->ExceptionOccurred())
{
classError = true;
emit error("JNI--Error running RegisterNatives");
stopGPSService();
return false;
}
else
{
emit error("JNI--Error running RegisterNatives");
stopGPSService();
return false;
}
}
The compiler gives me a warning:
warning: conversion from 'void (androidGPS: :) (JNIEnv, _jobject *, _jstring *)' to 'void *'
C ++ application crashes when calling sndonLocationChanged () in a class via JNI. I do not see an error in C ++, but Dalvik does not generate an error.
, , registerNatives ( ).
LocationChanged static :
static jboolean LocationChanged(JNIEnv* env, jobject object, jstring paramsString);
, paramsString !
, ?
,
.