08-11
15
java.lang.IllegalArgumentException: Illegal group reference
作者:Java伴侣 日期:2008-11-15
在用新闻模板做jsp新闻页面静态化转换的时候,程序老是出现
java.lang.IllegalArgumentException: Illegal group reference错误
经过网上查找,问题出在文章中含有$符号,replaceall()的源代码是:
while (cursor < replacement.length()) {
char nextChar = replacement.charAt(cursor);
if (nextChar == '\\') {
cursor++;
nextChar = replacement.charAt(cursor);
result.append(nextChar);
cursor++;
} else if (nextChar == '$') {
// Skip past $
cursor++;
// The first number is always a group
int refNum = (int)replacement.charAt(cursor) - '0';
if ((refNum < 0)||(refNum > 9))
throw new IllegalArgumentException(
"Illegal group reference");
cursor++;
可能问题就出在这里面对$符号的处理。那在处理文章内容(假设存储内容的字段为content)的时候加上
content.replaceA("$", "\\$")就可以将$符号替换写为\\$ ,这样就避免了错误的发生。
java.lang.IllegalArgumentException: Illegal group reference错误
经过网上查找,问题出在文章中含有$符号,replaceall()的源代码是:
while (cursor < replacement.length()) {
char nextChar = replacement.charAt(cursor);
if (nextChar == '\\') {
cursor++;
nextChar = replacement.charAt(cursor);
result.append(nextChar);
cursor++;
} else if (nextChar == '$') {
// Skip past $
cursor++;
// The first number is always a group
int refNum = (int)replacement.charAt(cursor) - '0';
if ((refNum < 0)||(refNum > 9))
throw new IllegalArgumentException(
"Illegal group reference");
cursor++;
可能问题就出在这里面对$符号的处理。那在处理文章内容(假设存储内容的字段为content)的时候加上
content.replaceA("$", "\\$")就可以将$符号替换写为\\$ ,这样就避免了错误的发生。
评论: 0 | 引用: 0 | 查看次数: 1278
发表评论