---
title: "How do you fix \"error: not a statement\" in Java?"
description: "Java reports not a statement when a line is an expression with no effect, such as a bare value or comparison. Add an assignment or call, or fix the typo."
url: "https://bugsee.com/answers/java/error-not-a-statement/"
---

# How do you fix "error: not a statement" in Java?

A line contains an expression that does nothing on its own, like `x + 1;` or `a == b;`. Assign the result, call a method, or correct the stray or misspelled token.

Only certain expressions can stand alone as a statement: assignments, increments, method calls and object creation. Anything else is rejected.

```java
int x = 5;

x + 1;            // error: not a statement, the result is discarded
x = x + 1;        // fine: assignment

x == 5;           // error: a comparison on its own does nothing
if (x == 5) { }   // fine: used in a condition

"hello";          // error: a bare value
System.out.println("hello");   // fine: a call

list.size;        // error: size is a method
list.size();      // fine
```

- Check the line above too: a missing semicolon or brace can make the next line look wrong.
- Misspelled keywords (`Int`, `retrun`) are read as identifiers and also give this error.
- Using `=` where you meant a method call, or `.` where you meant `;`, are common typos.

## Related questions

- [What does "Syntax error, insert Dimensions to complete ReferenceType" mean in Java?](https://bugsee.com/answers/java/insert-dimensions-to-complete-referencetype/)
