error reached end of file while parsing

Здравствуйте, начинаю изучать java по книге Head First — Java. понимаю что вопрос наверно детский, но у меня вылетает эта ошибка, и я не знаю в чём проблема, вроде скобки расставлены правильно, но она всё равно вылетает, Подскажите пожалуйста.

1 ответ 1

При вызове, как и при объявлении, метода обязательно нужно использовать скобки, даже если метод не принимает ни одного параметра. А после каждого оператора должна следовать точка с запятой.

Таким образом, вместо

Всё ещё ищете ответ? Посмотрите другие вопросы с метками java или задайте свой вопрос.

Связанные

Похожие

Для подписки на ленту скопируйте и вставьте эту ссылку в вашу программу для чтения RSS.

дизайн сайта / логотип © 2019 Stack Exchange Inc; пользовательское содержимое попадает под действие лицензии cc by-sa 4.0 с указанием ссылки на источник. rev 2019.11.15.35459

I have the following source code

When I try to compile it I get the following error:

What am I doing wrong? Any help appreciated.

4 Answers 4

You have to open and close your class with < . >like:

You need to enclose your class in < and >. A few extra pointers: According to the Java coding conventions, you should

  • Put your < on the same line as the method declaration:
  • Name your classes using CamelCase (with initial capital letter)
  • Name your methods using camelCase (with small initial letter)

Here’s how I would write it:

It happens when you don’t properly close the code block:

This is a compile error, easily fixed

The Java error message Reached End of File While Parsing results if a closing curly bracket for a block of code (e.g, method, class) is missing.

The fix is easy — just proofread your code.

Example

In the code below, the method called main does not conclude with a closing curly bracket. The compiler cannot parse the code properly and will throw the error.

Avoiding the Error

Because this error is both common and easily avoided, using a code editor like Visual Studio Code or an integrated development environment like Eclipse. Code editors that feature linters and syntax checkers for Java (or whatever language you use) will uncover errors before you attempt to compile.

Оцените статью
SoftLast
Добавить комментарий