• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

illegal character: \92

 
Michael Brewer
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying compile a class that I wrote. I get the following compile time exception:

I tried removing the semi-colon to see what other error it would give me, and it gives me the same error pointing now to the location that would have the semi-colon had it not been removed. I assumed this meant I somehow had a hidden character in there.
I deleted a lot of the text around that spot and retyped it, but I still get the same error.
I assume this is something very basic, and hopefully some of the long-timers have run into it before. Help please!
[ November 08, 2002: Message edited by: Michael Brewer ]
[ November 08, 2002: Message edited by: Michael Brewer ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right at the beginning of your string there is a closing quote: "<div class="
So the rest is crap to the compiler.
Frankly, don't write strings like that! Split them up nicely and concatenate them with the "+" operator.
-Barry
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better yet, use StringBuffer to build up complex strings; much more efficient than String concatentation.
Or even better yet, don't build up markup in strings! Either use a template system like JSP, or if you must build markup in Java, explore the use of packages like Jakarta ECS that allow you to build a DOM representing your markup as objects, and then serialize it to html, xhtml or other markup.
hth,
bear
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that if you concatenate string CONSTANTS, the compiler shoves them all together as one big string. So concatenation can be used at no cost to make long string constants more readable, as in:

which compiles to exactly the same bytecodes as:

Using StringBuffer.append in the above situation would be less readable and acutally less efficient:


Note also that non-constant string concatenation on a single line of code compiles to a usage of StringBuffer. The following two lines of code compile to identical bytecodes (JDK 1.4 - others are similar):

Actually, in many cases, using String.concat() can be more efficient (faster and creates fewer objects) than the above StringBuffer gunk, as in:

Just in case you wanted to know....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic