i hop you have the patience to help me with my now changed problem. i worked on my method to use less memory. it seems to be solved but another strange error occurs. before
i paste the method, i want to share my experiments:
first, my method works on all tested phone without any exceptions or errors. only the k700 and the t610 have problems (but in a slightly different way).
like you will see the core of the method is a tokenizer which goes through all characters and adds their width. if this width
is larger that a given size the character index returns to the last space-character and breaks into a new line.
the problem lies within the variable tokenIndex and its influence to the loop.
if i disable the addition of the char's width (that can happen in many lines) the midlet starts. if i dont do so, on k700 first the constructor loaded without an end.
then i noticed that i used special characters like 'ü' and 'ß' in my sentences.
after replacing them i only get an application error

i used lots of debug outputs and proofed that no index is used out of the string's boundaries (getCharAt(), substring()).
and my main argument: the identical midlet runs e.g. on my motorola v525.
now for those brave of you, the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| public String[] tokenizeText(String s, Font font, int areaWidth) { if( s == null ) return null; System.out.println("\n\n **** TOKENIZING **** "); System.out.println("tokenize: "+s); System.out.println("length of string "+s.length()); Vector newOrder = new Vector(); String resultStrings[]; int startToken = 0, lastSpace = 0; int currentRowWidth = 0; int row = 0; for(int tokenIndex=0; tokenIndex<s.length(); tokenIndex++) { currentRowWidth+=font.charWidth(s.charAt(tokenIndex)); if(s.charAt(tokenIndex) == ' ') lastSpace = tokenIndex; if(currentRowWidth >= areaWidth) { newOrder.addElement( s.substring(startToken, lastSpace) ); startToken = lastSpace+1; tokenIndex = lastSpace+1; currentRowWidth = 0; } } newOrder.addElement( s.substring(startToken) ); resultStrings = new String[newOrder.size()]; for(int i=0; i<newOrder.size(); i++) resultStrings[i] = (String)newOrder.elementAt(i);
return resultStrings; }
|