Passing Strings as argument in a native method

Hi,

I have to return from my C++ code a string. I have read that is not recommended to change the String object in the native function, so I chosen to work with StringBuffer. The problem is that when I call CallObjectMethod an exception is raised by StringBuffer.append : NullPointerException .

My code is:

//-- stringBuf is jobject function parameter

classStringBuffer = pEnv->GetObjectClass(stringBuf);

methodId = pEnv->GetMethodID(classStringBuffer, "append", "(Ljava/lang/String;)(java/lang/StringBuffer;");

pEnv->CallObjectMethod(obj, methodId, pEnv->NewStringUTF("a string"));

//--this is the place where the NullPointerException appears ...

I verified that CallObjectMethod return NULL.... I have no ideea where I wrong.

Please advise me!

Thanks and Regards,

Cosmin Petra

[872 byte] By [cosmin777] at [2007-9-26 9:03:49]
# 1
Well, one thing that is wrong is the method signature you are using to look up the method. Try this:methodId = pEnv->GetMethodID(classStringBuffer, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
bschauwe at 2007-7-1 20:08:04 > top of Java-index,Java HotSpot Virtual Machine,Specifications...