JAVAWarningSyntax ErrorMay 12, 2026

Syntax Error

Syntax error on token 'void', delete this token

What This Error Means

This error occurs when the Java compiler encounters a token it does not expect, such as a keyword in the wrong context. In this case, the 'void' keyword is being used as a method return type in an unexpected way.

Why It Happens

This error typically happens when a developer tries to use a method's return type in a way that is not syntactically correct. For example, trying to use a return statement outside of a method or trying to use a method as a variable.

How to Fix It

  1. 1To fix this error, you need to ensure that the 'void' keyword is being used correctly. In this case, you likely need to remove the return type from the method declaration or restructure your code to correctly use the method. Here is an example of how to fix the code:
  2. 2// Before (broken code)
  3. 3public void main(String[] args) {
  4. 4 System.out.println("Hello World");
  5. 5}
  6. 6// After (fixed code)
  7. 7public static void main(String[] args) {
  8. 8 System.out.println("Hello World");
  9. 9}

Example Code Solution

❌ Before (problematic code)
Java
public void main(String[] args) {
    System.out.println("Hello World");
}
✅ After (fixed code)
Java
public static void main(String[] args) {
    System.out.println("Hello World");
}

Fix for Syntax error on token 'void', delete this token

Related JAVA Errors

Related JAVA Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error