Почему выдает ошибку illegal start of expression?
Makaron3000, как наличие main в другом пакете могло повлиять на это? Скорее всего проблема была в другом. Либо вы запускали не тот класс. Например, вместо этого класса, другой класс, который удалили.
Ответы на вопрос 0
Ваш ответ на вопрос
Войдите, чтобы написать ответ

- Java
- +1 ещё
Как решить ошибку при запуске SpringBootAplication и шаблонизатора Mustache?
- 1 подписчик
- вчера
- 24 просмотра
How to Fix “Illegal Start of Expression” in Java

Over the past two and a half decades, Java has consistently been ranked as one of the top 3 most popular programming languages in the world [1], [2]. As a compiled language, any source code written in Java needs to be translated (i.e., compiled) into machine code before it can be executed. Unlike other compiled languages where programs are compiled directly into machine code, the Java compiler converts the source code into intermediate code, or bytecode, which is then translated into machine code for a specific platform by the Java Virtual Machine (JVM). This, in the simplest of terms, is how Java achieves its platform independence (Fig. 1).
One advantage that comes with being a compiled language is the fact that many errors stemming from incorrect language syntax and semantics (such as “illegal start of expression”) can be captured in the compilation process, before a program is run and they inadvertently find their way into production environments. Since they occur at the time of compilation, these errors are commonly referred to as compile-time errors.
The Java compiler can detect syntax and static semantic errors, although it is incapable of recognizing dynamic semantic errors. The latter are logical errors that don’t violate any formal rules and as such cannot be detected at compile-time; they only become visible at runtime and can be captured by well-designed tests.
When it encounters an error it can recognize, the Java compiler generates a message indicating the type of error and the position in the source file where this error occurred. Syntax errors are the easiest to detect and correct.

Illegal Start of Expression: What is it?
Expressions are one of the main building blocks of any Java application. These are constructs that compute values and control the execution flow of the program. As its name implies, the “illegal start of expression” error refers to an expression that violates some rule at the point where it starts, usually right after another expression ends; the assumption here is that the preceding expression is correct, i.e., free of errors.
The “illegal start of expression” error often arises from an insufficient familiarity with the language or due to basic negligence. The cause for this error can usually be found at the beginning of an expression or, in some cases, the entire expression might be incorrect or misplaced.
Illegal Start of Expression Examples
Access modifiers on local variables
A local variable in Java is any variable declared inside the body of a method or, more generally, inside a block. A local variable’s accessibility is predetermined by the block in which it is declared—the variable can be accessed strictly within the scope of its enclosing block. Therefore, access modifiers have no use here and, if introduced, will raise the “illegal start of expression” error (Fig. 2(a)). Removing the access modifier (as shown on line 5 in Fig. 2(b)) resolves the Java error.

Announcing Our New Java Error Monitoring SDK
Can Constructors Throw Exceptions in Java
How to Fix and Avoid NullPointerException in Java
«Rollbar allows us to go from alerting to impact analysis and resolution in a matter of minutes. Without it we would be flying blind.»
Вопрос №62311 от пользователя Фарид Сафаров в уроке «Строки», курс «Основы Java»
Расскажите, пожалуйста, подробнее, с какими сложностями вы столкнулись. Чтобы вам помочь, нужен контекст. С чем в итоге проблема?
[Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException make: *** [Makefile:5: test] Error 1 make: Leaving directory '/usr/src/app'
Ошибка компиляции возникает из-за некорректного синтаксиса. Метод System.out.println() принимает строку, которая оборачивается в двойные кавычки. И здесь нужно следить за тем, как эти кавычки расставлены. Сейчас в двойные кавычки заключена только вот эта част строки:
Хвост .\»» находится за пределами двойных кавычек. Это и вызывает ошибку компиляции.
Вопрос №48851 от пользователя Максим в уроке «Модуль 3. Урок 3. Уровни методов в Java.», курс «Введение в Java»
Привет. Возникла такая ошибка. Что это означает? ./src/io/hexlet/xo/view/ConsoleView.java:20: error: illegal start of type return game; ^ ./src/io/hexlet/xo/view/ConsoleView.java:20: error: expected return game; ^ Ревью — https://ru.hexlet.io/code_reviews/332981
return за пределами тела метода.
Используйте Хекслет по-максимуму!
- Задавайте вопросы по уроку
- Проверяйте знания в квизах
- Проходите практику прямо в браузере
- Отслеживайте свой прогресс
Рекомендуемые программы
