send string from c++ to java

Hello,I send a string (char *) from c++ to java as a inputargument for a method. This works great. But if the string consists of 1-3 character(s) it doesn't work ("Unhandled exception in...(JVM.dll)...Access violation.")Can anybody help?Thanks
[279 byte] By [XMAS1000a] at [2007-11-26 22:33:53]
# 1
What are you doing exactly?
Michael.Nazarov@sun.coma at 2007-7-10 11:41:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

sorry,

I do this:

C++:

char *c="hello";

//char *c = "hi";

jclass cls = env->FindClass(javaClassname);

jmethodID mid = env->GetStaticMethodID(cls, "draw", "(Ljava/lang/String;)[B");

jbyteArray jByteArr = (jbyteArray) env->CallStaticObjectMethod(cls, mid, c); *

Java:

public static byte[] draw(String param){

...

}

If c="hello" the program works perfectly. But if c="hi" (1-3 characters) the prog cancels on *.

XMAS1000a at 2007-7-10 11:41:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
How do you access passed variable. Are you sure program hangs in native code, not in java code?BTW I'm not sure it's valid to pass C pointer as is. Don't it be converted using env->NewStringUTF( p )?
Michael.Nazarov@sun.coma at 2007-7-10 11:41:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
Yeah, I checked specially for you :)You should usejbyteArray jByteArr = ( jbyteArray )env->CallStaticObjectMethod( cls, mid, env->NewStringUTF( c ) );
Michael.Nazarov@sun.coma at 2007-7-10 11:41:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
I think (jbyteArray) env->CallStaticObjectMethod(cls, mid, c)the error is that c should not be passed as a parameter.env->NewStringUTF( c) will be called before the above calling.
Sean.Hoa at 2007-7-10 11:41:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6
Yeah,thank you very much :-)
XMAS1000a at 2007-7-10 11:41:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...