Skip to main content

KNI_GetFieldID returns NULL

1 reply [Last post]
Joined: 2008-03-20

I try to access a instance member field of a Java class using the K Native Interface (KNI) from C++. Im using phoneME feature and try to extend the VM to support RS232. My code looks as follows:

Java_org_roastedkit_io_RS232Connection_connect0 ()
/* Declare handle */
KNI_StartHandles (3);
KNI_DeclareHandle (stringHandle);
KNI_DeclareHandle (objectHandle);
KNI_DeclareHandle (classHandle);

/* Get "this" pointer */
KNI_GetThisPointer (objectHandle);

/* Get instance class */
KNI_GetObjectClass (objectHandle, classHandle);

/* Get field id(s) */
jfieldID fidFD = KNI_GetFieldID (classHandle, "_fd", "I");
if (fidFD == NULL)
KNI_ThrowNew ("java/io/IOException", "Could not get field id");
/* Establish connection and set field _fd
* using KNI_SetIntField ( ... )
KNI_EndHandles ();
KNI_ReturnVoid ();

What really confuses me is the fact, that the same code already worked using the old kvm (j2me_cldc) from sun.

Hope somebody can help me with this.

Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-03-20

Thanks to the mailing list the problem could be solved. Here is the solution the mailing list member danila suggested:

"[i]Most likely this is because the field was renamed by romizer.
Romizer renames all fields that are not accessible by user code
(e.g. private fields, classes in hidden packages etc.)
This code might have worked for kvm, as kvm didn't do field renaming.

For phoneME Feature, if you need to access fields from native code,
you should disable field renaming for this class.

Add DontRenameNonPublicFields to the romizer configuration file.
Config file used for CLDC VM-only build is here: cldc/src/vm/cldc_rom.cfg
Config file used for full stack phoneME Feature build is here: cldc/src/vm/cldc_rom.cfg

The directive look like:

DontRenameNonPublicFields =

On the right hand is the full class name for which you want to disable field renaming.[/i]"