我尝试使用c和java之间的结构。为此,我创建了一个java类:
public class DriveInfo {
public String val1;
public String val2;
public String val3;
}
我在java函数中使用了:
private void getDriveInfos() {
DriveInfo newInfo = new DriveInfo();
newInfo.val1 = "Test";
getDriveInfo(newInfo);
logModel.add(logModel.getSize(), newInfo.val1);
}
getdriveinfo在jni接口中声明为:
private native int getDriveInfo(DriveInfo mClass);
JNIEXPORT jint JNICALL Java_JNIViie_getDriveInfo
(JNIEnv *env, jobject job, jobject jStruct);
JNIEXPORT jint JNICALL Java_JNIViie_getDriveInfo
(JNIEnv *env, jobject jobj, jobject jStruct){
jclass clazz;
jfieldID fid;
jstring buffer = env->NewStringUTF("myname");
clazz = env->GetObjectClass(jStruct);
fid = env->GetFieldID(clazz,"val1","Ljava/lang/String;");
if(clazz == 0){
return 0;
}
env->SetObjectField(clazz,fid,buffer);
return 0;
}
我以为 getDriveInfo
函数将打印出来 "myname"
不是 "test"
. 我现在的问题是,我做错了什么 val1
不要包含 "myname"
字符串?
暂无答案!
目前还没有任何答案,快来回答吧!