A
Allen
/********************* JAVA implementation
public class LogMesg {
public String loggerName;
public int length;
public byte[] buf;
}
public class LoggerAdapter {
public static native int readMesg(LogMesg logMesg);
static {
System.loadLibrary("demo");
}
}
/*********************************** C++ implementation
JNIEXPORT jint JNICALL Java_jni_logger_LoggerAdapter_readMesg
(JNIEnv *env, jclass cls, jobject obj)
{
// Lookup the String field ('loggerName') in 'obj'
jfieldID strLoggerNameFieldId = env->GetFieldID(cls, "loggerName",
"Ljava/lang/String");
if (strLoggerNameFieldId == 0)
{
printf("\nField [loggerName] not found");
return -1;
}
}
The program runs error saying that Field [loggerName] not found.
I think cls is an instance of LoggerAdapter, not a LogMesg.
But how to get loggerName field in this situation?
public class LogMesg {
public String loggerName;
public int length;
public byte[] buf;
}
public class LoggerAdapter {
public static native int readMesg(LogMesg logMesg);
static {
System.loadLibrary("demo");
}
}
/*********************************** C++ implementation
JNIEXPORT jint JNICALL Java_jni_logger_LoggerAdapter_readMesg
(JNIEnv *env, jclass cls, jobject obj)
{
// Lookup the String field ('loggerName') in 'obj'
jfieldID strLoggerNameFieldId = env->GetFieldID(cls, "loggerName",
"Ljava/lang/String");
if (strLoggerNameFieldId == 0)
{
printf("\nField [loggerName] not found");
return -1;
}
}
The program runs error saying that Field [loggerName] not found.
I think cls is an instance of LoggerAdapter, not a LogMesg.
But how to get loggerName field in this situation?