×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    white space-string prob

    i see white space in the form of rectangular boxes in mobile...but it works fine in emulator....i use String buffer...i know trim()...sample code ll be appreciated

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: white space-string prob

    Sounds like you are trying to display characters using an unsupported character set on the device.

    For example you will see this if you try to display simplified chinese on a european Nokia device as the simplified chinese font is not avaliable and so cannot be rendered.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  3. #3
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: white space-string prob

    Hi jselvakumar26071988,
    What Paul.Todd is Exactly correct , what ever you are assuming as a space it might be some special character . It might be the case like your emulator might have that character displaying capability but your phone doesn't have that character. You can verify this by using If you have a Text editor like VI . Save your data in that file and convert that file to hexMode you can figure it out what that character is.

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: white space-string prob

    Quote Originally Posted by jselvakumar26071988 View Post
    i see white space in the form of rectangular boxes in mobile...but it works fine in emulator....i use String buffer...i know trim()...sample code ll be appreciated
    Hi,
    As Paul.Todd has described that you are using a font to draw the string,which is not supported by the device..
    Are you using the system fonts or custom one..to draw the string...
    please provide the more information....
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: white space-string prob

    nothing extraordinary.....i tried rms complete reference code with few modification..i used string.buffer instead of writeutf..pl solve this prob..

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: white space-string prob

    We need more info!

    It sounds like you are writing and reading strings in RMS, right?

    So... you are converting between byte[] and String?

    I recommend you use ByteArrayOutputStream and ByteArrayInputStream, along with DataOutput and DataInput, and use writeUTF() and readUTF().

    Other methods of converting between byte[] and String tend to be unreliable. This is why you see the rectangle-characters.

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: white space-string prob

    Hi,
    Write the exact requirement here,
    Ig you want to read and write the string in RMS.
    Check how simple it is -
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import javax.microedition.rms.*;

    public class ReadWriteRMS extends MIDlet{
    private RecordStore rs = null;
    static final String REC_STORE = "ReadWriteRMS";

    public void startApp(){
    openRecStore();
    writeRecord("Core J2ME Technology");
    writeRecord("J2ME Wireless Toolkit");
    readRecords();
    closeRecStore();
    deleteRecStore();
    }

    public void pauseApp(){}

    public void destroyApp(boolean unconditional){
    notifyDestroyed();
    }

    public void openRecStore(){
    try{
    rs = RecordStore.openRecordStore(REC_STORE, true );
    }catch (Exception e){}
    }

    public void closeRecStore(){
    try{
    rs.closeRecordStore();
    }catch (Exception e){}
    }

    public void deleteRecStore(){
    if (RecordStore.listRecordStores() != null){
    try{
    RecordStore.deleteRecordStore(REC_STORE);
    }catch (Exception e){}
    }
    }

    public void writeRecord(String str){
    byte[] rec = str.getBytes();
    try{
    rs.addRecord(rec, 0, rec.length);
    }catch (Exception e){}
    }

    public void readRecords(){
    try{
    byte[] recData = new byte[5];
    int len;

    for(int i = 1; i <= rs.getNumRecords(); i++){
    if(rs.getRecordSize(i) > recData.length){
    recData = new byte[rs.getRecordSize(i)];
    }
    len = rs.getRecord(i, recData, 0);
    System.out.println("------------------------------");
    System.out.println("Record " + i + " : " + new String(recData, 0, len));
    System.out.println("------------------------------");
    }
    }catch (Exception e){}
    }
    }
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    158

    Re: white space-string prob

    modify it for dynamic,mixed record type....for e.g. to save the player name & score....and adding,deleting,updating process....that is the prob here...

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: white space-string prob

    Don't use String.getBytes(). It's not unicode safe.

    For maximum compatibility across devices, I always save all the game data in one record. Something like this:

    Code:
    private void saveGame() throws RecordStoreException, IOException {
    
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        DataOutput dout = new DataOutputStream(bout);
    
        // write any data you want
        dout.writeUTF(playerName);
        dout.writeInt(score);
    
        byte[] data = bout.toByteArray();
        
        RecordStore rs = RecordStore.openRecordStore(RECORDSTORE_NAME, true);
        try {
            if (rs.getNumRecords() == 0) {
                rs.addRecord(data, 0, data.length);
            }
            else {
                rs.setRecord(1, data, 0, data.length);
            }
        } finally {
            rs.closeRecordStore();
        }
    }

  10. #10
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: white space-string prob

    Quote Originally Posted by jselvakumar26071988 View Post
    modify it for dynamic,mixed record type....for e.g. to save the player name & score....and adding,deleting,updating process....that is the prob here...
    In addition to that RMS code you have to work on UI also,

    @ Just Take the name of the user,
    @ Store in string
    @ convert it into the byte array,
    @ Just write the bytes in RMS,

    Then Read the RMS as follows,
    @ Read the name from RMS
    @ Store the name in string
    @ Draw the string

    Same concept for the score ,
    This is a very efficient link here
    http://www.java2s.com/Code/Java/J2ME...gamescores.htm
    Just assign the name of the user,make it dynamic..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Trimming a String/ Removing White Spaces
    By JasonSmithMiller in forum Symbian
    Replies: 1
    Last Post: 2008-10-31, 05:42
  2. Replies: 5
    Last Post: 2008-06-13, 06:35
  3. Extra not wanted white space in XHTML MP ??!
    By mohsleem in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2006-04-27, 09:15
  4. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52
  5. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

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