语法错误'}'

时间:2014-09-29 16:08:20

标签: java indentation

它说我想念一个'},我不知道在哪里?我已经重新启动了eclipse,错误仍然存​​在......我有java的基础知识,但没有错?

    if(args.length > 0)
    {
        print("Started with arguments:");
        for(int i=0; i < args.length;i++)
        {
            print(args[i]);
        }
        for(int y=0; y < args.length;i++)
        {
            if(args[y].startsWith("PATH=") == true);
            {
                setEXEPath(args[y].substring(5));
            } //<-- THIS line
            else if(args[y].startsWith("DIRECTSTART=") == true)
            {
                if(args[y].substring(12).equals("true") == true)
                {
                    enableWorking();
                }
                else
                {
                    disableWorking();
                }
            }
        }
    }

2 个答案:

答案 0 :(得分:1)

问题是;之后的分号(if):

if(args[y].startsWith("PATH=") == true);

让我们来看看java如何解释这个:

// If some condition, do nothing - the ; terminates the if
if(args[y].startsWith("PATH=") == true);

// An anonymous block that's always called.
// As noted above, the if have been terminated.
{
    setEXEPath(args[y].substring(5));
}

// An else if!
// But this cannot be, as it does not follow an if's block!
// Hence, this is a syntax error.
else if(args[y].startsWith("DIRECTSTART=") == true)

答案 1 :(得分:0)

这是你的问题:

if(args[y].startsWith("PATH=") == true); <-- remove the semi colon