• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String.format() problem

 
ali honarmand
Ranch Hand
Posts: 32
Java Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I try to use String.format method as follows

String msg = String.format("%s: %d"+, message, customerId);

but receive the following error:

"illegal start of expression"

I don't know the reason. help please.

P.S. message and customerId are variables in my code.
 
Maneesh Godbole
Saloon Keeper
Posts: 11060
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ali honarmand wrote:
String msg = String.format("%s: %d"+, message, customerId);

Does this even compile for you?
Please PostRealCode
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, I believe "illegal start of expression" is the compiler error.

Although, Ali: if you look more closely at the compiler error, it does have some more information. In particular, look for the '^' character which points helpfully to the specific location where the compiler thinks the error is. This position is slightly misleading - the real error is one character to the left, in this case. Hope that helps...
 
Maneesh Godbole
Saloon Keeper
Posts: 11060
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Um, I believe "illegal start of expression" is the compiler error.

My bad.
Its ages I have seen a complier error like as on the console. I use eclipse and it flags them in red.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check all your indentation is correct, and that the braces {} all match up, and that your line is inside a method (or initialiser block). A common reason for that error is incorrectly matched braces and the line is in the class but not in a method.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ali honarmand wrote:


Look carefully at that line of code.

You have +, in there. Plus, comma. Remove the plus sign, it doesn't belong there.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what I was hinting at, yes.
 
ali honarmand
Ranch Hand
Posts: 32
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
ali honarmand wrote:


Look carefully at that line of code.

You have +, in there. Plus, comma. Remove the plus sign, it doesn't belong there.

Thanks, you helped.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic