This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String literals" Watch "String literals" New topic

String literals

Andrea Hampton

Joined: Feb 05, 2002
Posts: 2
I can't remember how I get this to print:
I have a StringBuffer that just says:
str.append ('<xml>MyXML</xml>');
I get an unclosed character literal error, because of the backslash. How do I get the backslash to print?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Its not the forward slash that is giving you the error, it is the way you are defining the String. It should be enclosed in double quotes " when you use single quotes the compiler thinks it is a char and not a String. If you just enclose it in double quotes it'll compile fine and you wont have to escape anything.
hope that helps

Consider Paul's rocket mass heater.
subject: String literals
Similar Threads
Conversion of Raw Soap Response Into HTML
Ajax response and accented characters (richfaces)
Need help with "Variable"
Error when using xml tags