aspose file tools*
The moose likes Java in General and the fly likes String.format() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "String.format() problem" Watch "String.format() problem" New topic
Author

String.format() problem

ali honarmand
Ranch Hand

Joined: Oct 12, 2009
Posts: 32

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.


A. Honarmand
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

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

Does this even compile for you?
Please PostRealCode


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Jul 26, 2007
Posts: 10523
    
    9

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

Joined: Oct 13, 2005
Posts: 39869
    
  28
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

Joined: Aug 16, 2005
Posts: 14350
    
  22

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
That is what I was hinting at, yes.
ali honarmand
Ranch Hand

Joined: Oct 12, 2009
Posts: 32

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.
 
Consider Paul's rocket mass heater.
 
subject: String.format() problem