Java:令牌上的语法错误" catch",(预期

时间:2015-11-01 00:14:24

标签: java syntax try-catch

我在Eclipse IDE中不断收到错误:

Syntax error on token "catch", ( expected

我不确定语法错误在哪里,有人可以帮忙吗?

public class ReadCSV {

    private static HashMap <String, String> rankDomainMap; 

    public ReadCSV() {
        rankDomainMap = new HashMap<>();
    }

    public HashMap getHashmap() {
        return rankDomainMap;
    }

    public void run(int id) {

        File top1m = new File("top-1m.csv");

        String line = "";

        int blockSize = 10000;

        try ( FileReader fileReader = new FileReader(top1m); BufferedReader br = new BufferedReader(fileReader) )
            {
                while ( ((line = br.readLine()) != null) ) {
                    String parts[] = line.split(",");
                    for (int count=1; count < blockSize; count++){
                        if ( (Integer.parseInt(parts[0]) >= (id) ) && (Integer.parseInt(parts[0])+blockSize < id) ) {
                                rankDomainMap.put(parts[0], parts[1]);
                        }
                    }
                }

            }


        System.out.println( rankDomainMap.toString() );

        catch (FileNotFoundException e)  {
            e.printStackTrace();
        }
    }
}

2 个答案:

答案 0 :(得分:6)

catch必须直接遵循try的结束括号。目前代码有一个System.out.println。

它需要看起来像这样:

ICacheClient

答案 1 :(得分:0)

您在}之前错过了catch