Currently in my application I am using C++(core implementation) and java(services and presentation). Now in my C++ core I am getting an exception, which I am catching in JNI code and creating a throwable object of it, and throwing it to java layer. So that it can be further processed.
For catching exception on jni I am using following code,
catch (namespace::MyException& excep) {
jclass ex = jenv->FindClass("namespace/MyException");
jmethodID constructor;
jthrowable object;
jobject obj;
if (ex)
{
constructor = jenv->GetMethodID(ex, "<init>", "(Ljava/lang/String;Ljava/lang/String;I;I)V");
if(!constructor)
{
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, (char*) excep.what());
return $null;
}
jstring str = jenv->NewStringUTF(excep.what());
jstring str2 = jenv->NewStringUTF(excep.GetStackTraceAsString());
obj = jenv->NewObject(ex, constructor, str, str2,excep.GetCat(),excep.GetCate());
object = static_cast<jthrowable>(obj);
jenv->DeleteLocalRef(str);
jenv->DeleteLocalRef(str2);
jenv->Throw(object);
}
return $null;
}
The C++ signature for my MyException Class is
MyException(string str1, string str2, int cat1, int cat2);
But in my Jni code I am not able to get methodId For MyException CTOR.
Can any one tell me what could have gone wrong in JNI code. What I suspect is that There is some Problem in parameterList in GetMethodId().
You should not have any semicolons between primitives in your signature. It should be like this:
Notice the
II, notI;I.Edit
You can always run
javap -s <package.name.ClassName>on your built classes.