Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

String.format() problem

 
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Does this even compile for you?
Please PostRealCode
 
Rancher
Posts: 4068
56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74723
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 4068
56
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is what I was hinting at, yes.
 
ali honarmand
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic