Reached End of file while parsing

痴心易碎 提交于 2019-12-02 10:13:23

Yes, you don't have enough closing braces.

One major point of confusion is that all of your code is in a single method (main) which in turn contains a method-local class (CalculateListener) which is 80 lines long.

Did you mean that to be a method-local class? Is there any reason why you want it to be a method-local class Did you just actually forget to "close" your main method? You don't even seem to use CalculateListener anyway, or do anything with the JFrame that main creates.

If you ask your IDE to indent your code for you, it should make it very clear when you have problems like this. Additionally, making your methods shorter and trying to reduce indentation can help. For example, in your actionPerformed method, the whole body of the method is within a single if block. If you just invert the logic of that if, you can save a level of nesting. You can then do the same with the next if block, too:

public void actionPerformed (ActionEvent ae)
{
    if (ae.getSource() != displayButton)
    {
        return;
    }
    resultTextArea.setText("");
    if (!readFile("input.txt"))
    {
        return;
    }
    for (int i=0; i < lines.length; i++)
    {
        if (i % 2 == 0)
        {
            // display the array elements to text area
            resultTextArea.append(lines[i]+"\n");
        }
    }
}

The problem seems to be with curly braces:

  1. Add 2 ending curly braces } after frame.add(panel); to close your main() method and class
  2. Remove } from last line
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!