How to use JNI registerNatives inside C ++ class?

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; //Return with error
        }
        else
        {
            emit error("JNI--Error running RegisterNatives");
            stopGPSService();
            return false; //Return with error
        }
    }

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 !

, ?

,

.

+3
1

, Java- androidGPS non-class LocationChanged(), androidGPS:: LocationChanged().

++ , , , .

+2

All Articles