evaluate strings in java from c++
Hi all,
first my c++-code
m_user ="debug";
jmethodID mid = m_vm.env->GetMethodID(m_vm.cls,"draw","(Ljava/lang/String;)[B");
if (mid == 0){
return FALSE;
}
jbyteArray jByteArr = (jbyteArray) m_vm.env->CallObjectMethod(m_vm.obj, mid, m_vm.env->NewStringUTF(m_user));
now my java-code:
publicbyte[] draw(String user){
...
if (user.equals("debug")){
System.out.println("CORRECT");
}else{
System.out.println("-"+user+"-");
}
...
}
The output is "-debug-". But it should be "CORRECT". Can anybody tell me why?
Thanks,
XMAS
[1245 byte] By [
XMAS1000a] at [2007-11-27 6:07:30]

# 1
> Hi all,
> first my c++-code
> > m_user = "debug";
> jmethodID mid = m_vm.env->GetMethodID(m_vm.cls,
> "draw", "(Ljava/lang/String;)[B");
>if (mid == 0) {
> turn FALSE;
>}
> eArray jByteArr = (jbyteArray)
> m_vm.env->CallObjectMethod(m_vm.obj, mid,
> m_vm.env->NewStringUTF(m_user));
>
>
> now my java-code:
> > public byte[] draw(String user){
>...
> if (user.equals("debug")){
>System.out.println("CORRECT");
> else {
>System.out.println("-"+user+"-");
>
>...
>
>
>
> The output is "-debug-". But it should be "CORRECT".
> Can anybody tell me why?
No. What does this code output for you?
// Java Code
public class StringTest {
static {
System.loadLibrary("stringtest");
}
public static void main(String[] args) {
callNative();
}
private static void doIt(String s) {
if (s.equals("debug")) {
System.out.println("CORRECT");
} else {
System.out.println("-" + s + "-");
}
}
private static native void callNative();
}
//Native code
#include "StringTest.h"
JNIEXPORT void JNICALL Java_StringTest_callNative
(JNIEnv *env, jclass cls)
{
jmethodID id = env->GetStaticMethodID(cls, "doIt", "(Ljava/lang/String;)V");
const char *user = "debug";
env->CallStaticVoidMethod(cls, id, env->NewStringUTF(user));
}
If this code works, then there is something wrong on your end, such as a rogue copy of your shared library with outdated code.
Jim S.