tags:

views:

102

answers:

0

I have trouble setting java object value in JNI. When run under debug mode, it always show this error:

DalvikVM[localhost:8664] - Thread[,#.main] (suspended(exception RuntimeException))

I don't know what's wrong with it. Can someone please help me out here. Many thanks in advance.

Below are my code:

[Data class]

package com.lib; public class Data {

public Data() {}

public int a;

}

[main java]

import com.lib.Data;

public class lib extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Data d = new Data();
d.a = 2; Set(d);

TextView tv = new TextView(this); tv.setText(d.a); }

static{ System.loadLibrary("Lib"); }

public static native void Set(Data d); }

[Jni implementation]

extern "C" {

JNIEXPORT void JNICALL Java_com_lib_lib_Set(JNIEnv* env, jclass c, jobject obj) {

jclass cls = env->GetObjectClass(obj);

jfieldID fid = env->GetFieldID(cls, "a", "I");

jint ret = 4;

env->SetIntField(obj, fid, ret); } }