Hi all,
I recently started writing applications for the Nokia 6131 NFC phone and have come unstuck with a rather tricky problem: StringItem.setFont() doesn't gaurantee that your selected font will be used, it merely hints that it is a "preferred font". To work around this I initially created a CustomItem and used Graphics.setFont() and Graphics.drawString(), but that introduced a new problem: how to wrap long text.
I finally discovered Text.paint() in the com.sun.midp.lcdui.Text package and it works very well at 1) respecting the requested font and 2) wrapping text in the selected area. The following code snippet demonstrates how I use it:
This runs perfectly on the Nokia emulator but when deployed to the phone I get the following application error: No Class Def Found Error java/lang/NoClassDefFoundError com/sun/midp/lcdui/TextCode:import javax.microedition.lcdui.*; import com.sun.midp.lcdui.Text; public class CustomItemLabel extends CustomItem { Display _display; Font _font; private String _label; ... protected void paint(Graphics g, int width, int height) { // paint background g.setColor(_display.getColor(Display.COLOR_HIGHLIGHTED_BACKGROUND)); g.fillRect(0, 0, width-1, height-1); // draw text g.setColor(_display.getColor(COLOR_FOREGROUND)); g.setFont(_font); g.translate(4, 4); Text.paint(_label, _font, g, width-8, Text.getHeightForWidth(_label, _font, width-8, 0), 0, (Text.NORMAL | Text.TRUNCATE), null); } }
As far as I can tell, this package is included in cldcapi11.zip and is located in the default Nokia NFC SDK installation directory C:\Nokia\Devices\Nokia_6131_NFC_SDK_1_0\lib which appears to automatically be included when one creates a new J2ME project. One would assume that it is also part of the CLDC 1.1 runtimes which are preinstalled on the phone.
So, why do I get this error? And why, if com.sun.midp.lcdui.Text is included in CLDC 1.1, does the error go away when I manually copy Text.class into my deployed .jar? This is a workaround but it does mean that I can't sign my MIDlets!
Can anyone help? Is this a bug on the Nokia 6131?
Best regards,
Cord

Reply With Quote

