views:

181

answers:

5

For the life of me, I can't understand why adding a concatenated string to the MainScreen is causing the BB simulator to throw an exception. If I run a VERY simple hello program with the following control, all is well:

RichTextField rtfHello = new RichTextField("Hello There !!!");        
add(rtfItemDescription);

But if I add a concatenated string, the entire app breaks:

String MyName = "John Doe";
RichTextField rtfHello = new RichTextField("Hello There !!!" + MyName);        
add(rtfItemDescription);

So what am I doing wrong? Why would the simulator throw an exception for the second example?

A: 

Not sure why it would blow up (but I'm not a blackberry/java developer). Have you simply tried:

String MyName = "John Doe"; 
String HelloString = "Hello There !!!";
RichTextField rtfHello = new RichTextField(HelloString.concat(MyName));         
add(rtfItemDescription); 

Or simply,

String MyName = "John Doe"; 
RichTextField rtfHello = new RichTextField("Hello There!!!".concat(MyName));         
add(rtfItemDescription); 
George
A: 

I don't think problem is with string concatenation. can provide more information like what exception you are getting.

Vivart
it looks as that when i do any string concatenation in my blackberry project (using eclipse), the packaging process cannot find the definition of the class StringBuilder. the project is defaulted to jdk 1.4. StringBuilder wasn't introduced until version 1.5 so attempting to run the code will produce a "no class definition found" error message. So this is my guess as to why i am seeing my errors.
sexitrainer
A: 

looks as that when i do any string concatenation in my blackberry project (using eclipse), the packaging process cannot find the definition of the class StringBuilder. the project is defaulted to jdk 1.4. StringBuilder wasn't introduced until version 1.5 so attempting to run the code will produce a "no class definition found" error message. So this is my guess as to why i am seeing my errors. – sexitrainer Jan 20 at 15:30

This is because StringBuilder is not a part of J2ME. You won't be able to use it while programming for mobile devices.

gaboalonso
A: 

For string concatenations in Blackberry try to use StringBuffer class. StringBuffer is faster than String, because it mutable.

Yeti
+1  A: 

Try this

String MyName = "John Doe";
    RichTextField rtfHello = new RichTextField("Hello There !!!" + MyName);        
    add(rtfHello);
Alex