×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    5

    Question No Class Def Found Error com/sun/midp/lcdui/Text

    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:
    Code:
    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);		
      }
    }
    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/Text

    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

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: No Class Def Found Error com/sun/midp/lcdui/Text

    com.sun.midp.lcdui.Text is an implementation class for the emulator. It is not part of the public API, and there is no guarantee that every device's implementation will have it. Your apps can only rely on classes that are part of the relevant CLDC or MIDP APIs.

    If you want text wrapping with drawString() you have to implement your own.

    shmoove

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    5

    Re: No Class Def Found Error com/sun/midp/lcdui/Text

    Thanks for the prompt reply shmoove.
    Quote Originally Posted by shmoove
    com.sun.midp.lcdui.Text is an implementation class for the emulator. It is not part of the public API, and there is no guarantee that every device's implementation will have it. Your apps can only rely on classes that are part of the relevant CLDC or MIDP APIs.
    This is where I'm confused. com.sun.midp.lcdui.Text is distributed in both the official Nokia NFC SDK and the official Sun JavaTM Wireless Toolkit for CLDC Version 2.5 (in midpapi20.jar). Why are they available (and indeed used by:

    javax.microedition.lcdui.Alert,
    javax.microedition.lcdui.ChoiceGroup,
    javax.microedition.lcdui.CustomItem,
    javax.microedition.lcdui.DateField,
    javax.microedition.lcdui.Displayable,
    javax.microedition.lcdui.Gauge,
    javax.microedition.lcdui.ImageItem,
    javax.microedition.lcdui.Item,
    javax.microedition.lcdui.StringItem and
    javax.microedition.lcdui.TextField.

    I'm sure there are probably others..

    Does this mean that if we want to use com.sun.midp.lcdui.Text, we should include it in our MIDlet? And if so, how does one do that with Eclipse and EclipseME?

    Btw, I've already seen the link that you posted while trawling through the forum. I'll consider using it if Text.paint() is not an option..

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: No Class Def Found Error com/sun/midp/lcdui/Text

    Quote Originally Posted by cord.schneider
    This is where I'm confused. com.sun.midp.lcdui.Text is distributed in both the official Nokia NFC SDK and the official Sun JavaTM Wireless Toolkit for CLDC Version 2.5 (in midpapi20.jar). Why are they available
    The idea with Java is that you have an API, manufacturers make VMs that are required to follow the API. How they do it doesn't matter. The class comes with both SDKs because the Nokia SDK is based on the Sun SDK, and Sun's emulator uses it. But is not in the API, so the phones don't have it.

    shmoove

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    5

    Re: No Class Def Found Error com/sun/midp/lcdui/Text

    Phew, thanks for the explanation shmoove! It clears up the mystery somewhat and does mean that I'll have to write my own support, or use a third-party library.

Similar Threads

  1. Java Application running on WTK but not on S60 SDK
    By roman.benz in forum Mobile Java Tools & SDKs
    Replies: 6
    Last Post: 2009-06-09, 14:38
  2. External Linking Error (Undefined Symbol)
    By nile_mail in forum Symbian
    Replies: 2
    Last Post: 2008-08-05, 13:10
  3. Linking Error(Undefined Symbol)
    By nile_mail in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 10
    Last Post: 2008-03-26, 23:32
  4. send array[0] different class
    By gift_te in forum Symbian
    Replies: 0
    Last Post: 2007-03-28, 13:04
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×