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 ;D
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:
/**
* Tries to break a long line of text into several shorter ones, so that
* the width of the produced lines is never wider that <i>areaWidth</i>.
* The width of the strings is calculated by the width of each appearing
* character using the charWidth() method of the given font object.
*
* TODO: method fails if the string has no breaking points (spaces) and
* is larger than areaWidth
* */
public String[] tokenizeText(String s, Font font, int areaWidth)
{
// valid string ?
if( s == null ) return null;
System.out.println("\n\n **** TOKENIZING **** ");
System.out.println("tokenize: "+s);
System.out.println("length of string "+s.length());
// contains the new formatted text block, each entry means a text row
Vector newOrder = new Vector();
// the string array which is returned by this method as result
String resultStrings[];
int startToken = 0, lastSpace = 0;
int currentRowWidth = 0;
int row = 0;
// checking all characters
for(int tokenIndex=0; tokenIndex<s.length(); tokenIndex++)
{
currentRowWidth+=font.charWidth(s.charAt(tokenIndex));
// marking a space as return point for line break
if(s.charAt(tokenIndex) == ' ')
lastSpace = tokenIndex;
// if the width of all checked chars exeeds the boundaries
// return to the last marking point and access new line (next array field)
if(currentRowWidth >= areaWidth)
{
// creating one row of text, fitting into boundaries
newOrder.addElement( s.substring(startToken, lastSpace) );
// marking start (and end) of characters to convert
startToken = lastSpace+1;
tokenIndex = lastSpace+1;
currentRowWidth = 0;
}
}
// formatting the remaining chars to row
newOrder.addElement( s.substring(startToken) );
// convert vector of strings into string array
resultStrings = new String[newOrder.size()];
for(int i=0; i<newOrder.size(); i++)
resultStrings[i] = (String)newOrder.elementAt(i);
return resultStrings;
}