我的Java代码(嵌入在JSP中)中的try / catch语句失败,并出现以下错误:
An error occurred at line: 26 in the jsp file: /template/tampabay/includes/omniture-footer.jsp
Syntax error on token "}", delete this token
我无法确定以下代码产生该错误的原因:
<%!
/*
* Map the DTI categories to the appropriate SiteCatalyst category
* structure.
*/
ArrayList<HashMap> mapDTIToSiteCatalystCategories( ArrayList<HashMap> dti_categories ) {
ArrayList<HashMap> site_catalyst_categories = new ArrayList<HashMap>();
ArrayList<Integer> dti_category_ids = new ArrayList<Integer>();
for ( int i = 0; i < 4; i++ ) {
try {
dti_category_ids.add( Integer.parseInt( (String)dti_categories.get( i ).get( "id" ) ) );
}
catch ( NumberFormatException e ) {
dti_category_ids.add( -1 );
}
}
// - Snip -
}
错误对应于上面的第十二行(try
语句的结束括号)。但是,代码看起来在语法上对我来说是正确的。除了通过在JSP中嵌入scriptlet而违反协议,你能指出错误吗?
我尝试使用此代码的变体(删除for
循环并声明单独的变量)但每当我尝试使用try / catch语句时错误仍然存在。
修改:
我上传了the complete code listing here.
编辑2 : 我还收到以下错误:
An error occurred at line: 44 in the jsp file: /template/tampabay/includes/omniture-footer.jsp
Syntax error, insert "}" to complete Block
此错误对应于以下第四行:
"", "Baseball",
"", ""
);
break;
case 120: // Baseball: Minors
site_catalyst_categories = addElements(
dti_category_ids.get( 0 ), "Sports",
之前我没有包含它,因为我认为它是由早期错误引起的。但是,根据评论,它可能是相关的。
根据我的IDE和我的目视检查,所有支架都已正确配对。但是,编译器不同意。
答案 0 :(得分:3)
看起来,在第131/132行,try语句缺少密集卷曲。
case 131:
try {
switch ( dti_category_ids.get( 2 ) ) {
case 252: // Colleges: Bulls ..snip..
case 253: // Colleges: Bulls ..snip..
case 254: // Colleges: Bulls ..snip..
default: // Log all others to the "College" section
}
break;
// HERE ... THERE'S NO } TO CLOSE THE try {
catch ( NumberFormatException e ) {
// Log all others to the "College" section
site_catalyst_categories = addElements(
dti_category_ids.get( 0 ), "Sports",
"", "College",
"", "",
"", ""
);
}