Skip to main content

How to use CNI when a native method is statemented in a j2me midlet?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-12-20
Points: 0

j2me code:
package game.lib;
public class StbInfo
public static native void getstbinfo();
the question is:
how can I implement this native method in jvm code?
where should I insert the code?
thank you for your help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-10-16
Points: 0

I assume you are getting some sort of link error for the missing getstbinfo() method. Native methods for MIDP and midlets are implemented as KNI methods. When running on CDC/CVM, KNI methods are implemented as CNI methods with special KNI macros, so when missing you probably see the method name as CNIgame_lib_StbInfo_getbsdinfo.

The way to get the KNI native method so it can be built for CLDC or CDC is to use the KNIDECL macro. You can find it in kni.h, but there is a different version of the header depending on whether you are building for CLDC or CDC. For CDC, make sure you are using the one in cdc/src/share/export/kni.h. You should be able to find plenty of examples of the use of KNIDECL in the midp source.