About CallByteMethodA Function

Hi you all:

I have some problem about CallByteMethodA function.

This is what my java code looks like:

public void setDS_INFO_mac(byte[] mac) {

for( int i = 0; i < mac.length; ++i ) {

this.ds_info.mac = mac;

}

}

This is what my c code looks like:

jobject objref;

jclass cls = NULL;

jfieldID fid = NULL;

jmethodID mid = NULL;

jbyte dsMac[6];

jbyteArray returnArray = 0;

...

/* code not pertaining to this question snipped. */

mid = env->GetMethodID(cls, "setDS_INFO_mac", "([B)V" );

for( int j = 0; j < 6; ++j ) {

dsMac[j] = search_Info.ds_info.mac[j];

}

returnArray = env->NewByteArray(6);

if( returnArray != NULL ) {

env->SetByteArrayRegion(returnArray, 0, 6, (jbyte*)dsMac);

env->CallByteMethodA(objref, mid, (jvalue*)returnArray);

env->DeleteLocalRef(returnArray);

}

This is not working.

and, some about run time exception as follows:

Exception in thread "main" java.lang.NullPointerException

at CFGINFO.setDS_INFO_mac(DSCIStructure.java:97)

at DSCIJNInterface.dsc_EnumSearch(Native Method)

at MainApp.searching(MainApp.java:105)

at MainApp.main(MainApp.java:46)

Any idea what I'm doing wrong?

[1365 byte] By [shiannjia] at [2007-11-26 19:38:52]
# 1
Hello, maybe someone can share an example about this function, thank you very much.
shiannjia at 2007-7-9 22:17:26 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
You are missing error checking code. Many calls to the JNI interface require that you check the method return value. Many calls also require that java exceptions must be checked for after the call.
jschella at 2007-7-9 22:17:26 > top of Java-index,Java HotSpot Virtual Machine,Specifications...