United States · High school and college · Java compiler errors

Java “cannot find symbol”: what it means and how to fix it

You press compile and Java answers with “error: cannot find symbol”, a caret under one word, and two indented lines that look like a riddle. The message is far more helpful than it seems. It names the exact word the compiler could not match to any declaration, says what kind of thing it expected that word to be, and tells you where it was searching. This guide reads the message line by line from programs we compiled ourselves, lists the eight mistakes that cause nearly every case a student meets, and gives you a numbered routine for fixing it in BlueJ, Eclipse, IntelliJ IDEA, VS Code or a browser editor.

Live teaching since 2020 · 10,000+ students · Java from first class to AP CSA

In short

The error “cannot find symbol” means the Java compiler met a name (a variable, method or class) that it could not match to any declaration it can see from that spot. The symbol line names the word, the location line says where Java looked. Usual causes: a typo or wrong capital letter, a variable used outside its block, or a missing import. Modern Age Coders teaches this live online for US students, in a batch or one to one, and the first class is free.

Learn it with a teacher

Three Java courses that turn compiler errors into understanding

Each one is live, and each one starts from the code your student is writing right now.

Reading the message

The four parts of a cannot find symbol error

We wrote a ten-line program with two deliberate mistakes and compiled it with javac 22.0.1. Here is the program, then exactly what the compiler printed.

The program · Grades.javajava
// Grades.java (ours): two mistakes on purpose
public class Grades {
    public static void main(String[] args) {
        int total = 0;
        for (int i = 1; i <= 3; i++) {
            int score = i * 10;
            total = total + score;
        }
        System.out.println("Last score: " + score);
        System.out.println("Total: " + Total);
    }
}

Ours. Line 8 uses score after the loop that declared it has ended; line 9 writes Total with a capital T.

What javac printedconsole
> javac Grades.java
Grades.java:8: error: cannot find symbol
        System.out.println("Last score: " + score);
                                            ^
  symbol:   variable score
  location: class Grades
Grades.java:9: error: cannot find symbol
        System.out.println("Total: " + Total);
                                       ^
  symbol:   variable Total
  location: class Grades
2 errors

Our run, javac 22.0.1 on Windows 11, 17 October 2026. Two separate errors, one per unmatched name.

Each line of the message, decoded (our reading of the run above)
PartIn our runWhat it tells you
File and lineGrades.java:8Open that file and go to that line first. The mistake is almost always on it or just above it.
Error nameerror: cannot find symbolThe compiler hit a word it could not connect to anything declared. Nothing was run yet.
CaretThe ^ under scoreThe exact word the compiler choked on, not the start of the line.
symbol:variable scoreWhat kind of name Java expected: variable, method (with argument types), or class.
location:class GradesWhere Java was searching. For a member it reads, for example, variable s of type String.

Why one mistake can look like several

Java reports each unmatched name separately, so two mistakes produce two errors and the summary line says 2 errors. A missing import is worse: in our runs, one forgotten import of ArrayList printed two errors on the same line, one for the type name and one for the constructor after new.

Fix the first error in the list, compile again, and only then look at the rest. Counting errors is a poor measure of how broken a program is.

What the compiler did not do

Oracle’s own troubleshooting page puts it plainly: if you see any compiler errors, the program did not successfully compile and the compiler did not create a .class file. So there is nothing to run until every error is gone.

That is also why an old version of your program sometimes seems to run in an IDE after a failed compile: you are running the last class file that did build, not the code on your screen.

Sources: our javac 22.0.1 run (raw output kept with our notes), and Oracle, Common Problems (and Their Solutions), read 17 October 2026. We are not connected with Oracle.

Eight causes

The eight mistakes behind almost every cannot find symbol

Every row below is a mistake we typed on purpose and compiled. The middle column is the symbol line javac printed, word for word, so you can match your own message against it.

Cause, symbol line and fix (our javac 22.0.1 runs, 17 October 2026)
Causesymbol: line we gotThe fix
1. Wrong capital lettervariable TotalJava treats total and Total as different names. Match the declaration exactly.
2. Variable used outside its blockvariable scoreDeclare it before the block that changes it, so it still exists afterwards.
3. Loop counter used after the loopvariable kA counter declared in the for header ends with the loop. Keep a separate variable if you need the value later.
4. Missing importclass ArrayListAdd import java.util.ArrayList; above the class. The same goes for Scanner and Random.
5. Misspelled methodmethod lenght()Check the spelling against the documentation or the Java Quick Reference.
6. Method or field that does not exist on that typevariable length (on a String)Strings use length() with brackets; arrays use .length without; an ArrayList uses size().
7. Method you never wrotemethod printReport(int[])Write the method, or fix the call so its name and argument types match one you wrote.
8. Class the compiler cannot seeclass StudentPut Student.java in the same project folder or package, and compile it too.
Causes 5 to 7, as the compiler reported themjava
// Roster.java (ours): four member mistakes, javac 22.0.1 output
String s = "hello";
System.out.println(s.length);     // field that does not exist
  symbol:   variable length
  location: variable s of type String

System.out.println(s.lenght());   // misspelled method
  symbol:   method lenght()
  location: variable s of type String

int[] scores = {90, 85, 77};
System.out.println(scores.length());   // arrays use .length
  symbol:   method length()
  location: variable scores of type int[]

printReport(scores);              // method never written
  symbol:   method printReport(int[])
  location: class Arrays1

Ours: lines trimmed from two of our test files to the code and the symbol and location lines. Read the location line: variable scores of type int[] tells you Java looked for length() on an array, where it does not exist.

Scope, the idea behind causes 2 and 3

The Java Language Specification defines it precisely: the scope of a local variable declared in a block is the rest of the block. In plain words, a variable born inside a pair of curly braces dies at the closing brace.

That is why score in Grades.java was fine inside the loop and unknown one line below it. Moving the declaration up, before the loop, widens its scope to the rest of main.

Imports, the idea behind cause 4

Oracle’s tutorial says the compiler automatically imports two entire packages for each source file: java.lang and the package your file is in. String, Math and System live in java.lang, which is why they never need an import.

ArrayList, Scanner and Random live in java.util, which is not imported for you. Either write the import line or use the fully qualified name, java.util.ArrayList.

Sources: Oracle, Variables (“Variable names are case-sensitive.”) and Using Package Members; Java Language Specification, Java SE 21, chapter 6. All read 17 October 2026.

Fix it yourself

A seven-step routine for any cannot find symbol error

This is the order we teach. It works in any editor, because it relies only on what the compiler printed, not on a particular IDE.

  1. Go to the first error only. Open the file and line it names. Ignore the error count for now.
  2. Read the symbol line aloud. “variable Total”, “method lenght()”, “class Scanner”. Saying the kind of name out loud tells you which half of the table above to look in.
  3. Search for the declaration. Use Find in your editor for the exact word. If you find it with different capitals or spelling, that is your fix.
  4. If it is declared, check the braces. Is the declaration inside a block (a loop, an if, another method) that has already closed by the line with the error? Then move the declaration up.
  5. If it is a class, check imports and files. Library classes need an import line; your own classes need their .java file in the same project or package.
  6. If it is a method, read the location line. It names the type Java searched. Look that type up in the documentation and check the method really exists there, with those argument types.
  7. Compile again after each single change. One fix, one compile. A second error often disappears on its own, and if a new one appears you know exactly which edit caused it.
The repaired program · Fixed.javajava
// Fixed.java (ours): score declared before the loop,
// total spelled the way it was declared
import java.util.ArrayList;

public class Fixed {
    public static void main(String[] args) {
        int total = 0;
        int score = 0;
        for (int i = 1; i <= 3; i++) {
            score = i * 10;
            total = total + score;
        }
        System.out.println("Last score: " + score);
        System.out.println("Total: " + total);

        ArrayList<String> names = new ArrayList<>();
        names.add("Ada");
        System.out.println(names.size());
    }
}

> javac Fixed.java && java Fixed
Last score: 30
Total: 60
1

Ours, compiled and run with javac and java 22.0.1. Declaring score before the loop and spelling total consistently clears both errors; the import line makes ArrayList visible.

Why we do not just hand out the fix

When a student brings a homework file to class, we do not type the correction for them, and we never supply answers to graded assignments. The teacher asks which word the caret points at and what the symbol line says, and the student finds the declaration.

Fixing ten of these errors yourself is the quickest way we know to see where a variable lives, which is what stops the scope mistake.

When the routine runs out

If the name is declared, spelled right, in scope and imported, and the error still appears, the problem is usually the build: a file outside the project, a stale class file, or two classes with the same name in different packages.

That is the moment to ask a person. A teacher who can see the whole project on a shared screen will usually spot it in a minute.

Same error, other words

What the same mistakes look like in Eclipse and other editors

BlueJ, VS Code and IntelliJ IDEA usually show javac’s wording or something close to it. Eclipse ships its own compiler, so its messages read differently. We compiled the same files with the Eclipse Compiler for Java to give you the translation.

javac wording against Eclipse compiler wording (our runs of javac 22.0.1 and ecj 3.46.100, 17 October 2026)
Mistakejavac saysEclipse compiler says
Wrong capital lettercannot find symbol, symbol: variable TotalTotal cannot be resolved to a variable
Missing importcannot find symbol, symbol: class ArrayListArrayList cannot be resolved to a type
Misspelled methodcannot find symbol, symbol: method lenght()The method lenght() is undefined for the type String
length() on an arraycannot find symbol, symbol: method length()Cannot invoke length() on the array type int[]
Class not in the projectcannot find symbol, symbol: class StudentStudent cannot be resolved to a type

Red underlines before you compile

Most editors check your code as you type, so the red squiggle under a word is the same complaint arriving early. Hovering over it shows the message, and the fix routine above still applies.

An underline that will not go away after you correct the spelling usually means the editor has not saved or rebuilt yet. Save the file and give it a moment.

Quick fixes: useful, with care

Editors offer one-click fixes such as adding an import or creating a missing variable. Adding an import is almost always right. Creating a variable to silence the error is almost always wrong, because it hides the real mistake, which was a typo or a scope problem.

Our rule for students: accept a quick fix only if you can say in one sentence why it is correct.

A close relative

Identifier expected: the error students confuse with this one

Searches for cannot find symbol often sit next to searches for identifier expected, especially from BlueJ users. They are different problems: one is about names, the other about where code is allowed to go.

Statements outside a method · Ident.javajava
// Ident.java (ours): statements outside any method
public class Ident {
    int count = 0;
    count = 5;
    System.out.println(count);
}

> javac Ident.java
Ident.java:3: error: <identifier> expected
    count = 5;
         ^

Ours, javac 22.0.1. The full run printed three of these errors, two of them on line 4. A declaration with a value is allowed directly in a class; an assignment or a println is not, so it must go inside a method such as main.

Telling the two errors apart (our summary of the runs on this page)
cannot find symbolidentifier expected
What went wrongA name is used that Java cannot match to a declarationJava expected a name at a point where the grammar needs one
Typical causeTypo, scope, missing importA statement placed directly in the class body, or a missing bracket
Where to lookThe declaration of the word under the caretThe braces around the line: is it inside a method?
First fix to tryMatch spelling and capitalsMove the statement into main or another method

AP Computer Science A

Why this error matters for AP Computer Science A

AP CSA students meet cannot find symbol constantly, because the course leans on exactly the features that trigger it: objects, String methods, ArrayList and arrays. Here is what College Board publishes about the exam, and how it connects.

AP Computer Science A exam facts, from AP Central (read 17 October 2026)
PointWhat College Board says
Format“This is a fully digital exam.” Students answer in the Bluebook testing app.
Reference sheetThe Java Quick Reference “lists the accessible methods from the Java library that may be included on the exam”.
Free responseSection II: 4 questions in 1 hour 30 minutes. Question 3 works with an ArrayList, Question 4 with a 2D array.
Biggest unitUnit 4, Data Collections, carries 30% to 40% of the multiple-choice weighting.
2027 dateMay 12, 2027, as listed on the AP Central exam page.

The connection, in our experience

Cause 6 in our table, mixing up length, length() and size(), is precisely the confusion between arrays, String and ArrayList that Unit 4 tests. A student who can say from memory which one each type uses has learned something the exam rewards.

The Java Quick Reference is the official list of the library methods you may meet on the exam, so it doubles as the reference to check when the compiler says a method does not exist.

Practicing without a compiler

On the free-response section you write code for a reader, not for javac, so nobody prints cannot find symbol for you. Our advice: once a week, write a short method on paper, then compile it and count the names the compiler could not find.

That count dropping over a semester is a better sign of readiness than any single practice score. For course planning, see our AP Computer Science A classes and what changed in AP CSA for 2026.

Sources: AP Computer Science A Exam and AP Computer Science A Course, AP Central, read 17 October 2026. AP is a trademark of College Board, which is not connected with this page or with us.

Practice set

Six lines to test yourself

Our own practice set. Each line compiles with exactly one cannot find symbol error. Before you look at the right-hand column, predict the symbol line javac will print. We checked every answer with javac 22.0.1.

Predict the symbol line (ours; answers from our javac 22.0.1 run)
Line of codesymbol: line javac printed
String name = "Ada"; then println(Name)variable Name
Math.squareRoot(16)method squareRoot(int), location: class Math
int[] a = new int[3]; then a.size()method size(), location: variable a of type int[]
Random r = new Random(); with no importclass Random
name.toUppercase()method toUppercase(), location: variable name of type String
println(k) after for (int k = 0; k < 3; k++)variable k

If you got the kind of symbol right on all six, you can read this error. If the Math line caught you out, the method you wanted is Math.sqrt. For more on reading errors in general, try our guide on how to debug code, and for a first course, Java for beginners.

From stuck to fluent

Four stages of reading Java errors

Where most students are when they first search for this error, and where practice takes them.

How students grow with compiler errors (ours)
StageWhat it looks like
1. AlarmedSees a wall of red text and starts changing lines at random
2. LocatingGoes to the file and line number, finds the word under the caret
3. DiagnosingReads the symbol and location lines and names the cause
4. PreventingDeclares variables in the right place and rarely sees the error at all

For parents

A teen who is frustrated by compiler errors is not failing at programming. They are at stage 1, which every programmer passes through.

What helps most is someone asking good questions about the message, rather than fixing the code for them.

For students

The compiler is precise, not hostile. It tells you the word, the kind of name and where it looked.

Fix one error, compile, repeat. Patience here is faster than guessing.

The catalogue

Nine courses for Java students and the languages around it

Nine live courses chosen for students who write Java at school now, or who are about to.

I

Java first

Teens

JCFS / JAVA / 01

Java for teens

From first class to objects and lists.

Open the syllabus

JCFS / JAVA / 02

AP Computer Science A

The College Board course, unit by unit.

Open the syllabus

JCFS / JAVA / 03

Problem solving for teens

Logic and data structures behind the code.

Open the syllabus
II

Alongside Java

Teens

JCFS / NEXT / 01

AP Computer Science Principles

The wider course, with the Create task.

Open the syllabus

JCFS / NEXT / 02

Python for teens

A second language with friendlier errors.

Open the syllabus

JCFS / NEXT / 03

Git and GitHub for teens

Save every working version of your code.

Open the syllabus
III

College and beyond

Ages 18 and up

JCFS / PRO / 01

Java for college

Intro CS Java, then real applications.

Open the syllabus

JCFS / PRO / 02

Data structures and algorithms

The course after the intro sequence.

Open the syllabus

JCFS / PRO / 03

Competitive programming

USACO-style problems in Java or C++.

Open the syllabus

How lessons run

Live Java classes that fit a US school week

Weekdays or weekends, flexible: choose your batch, or for a very personalised plan choose 1-on-1 at your convenience, weekend mornings or weekdays.

Weekdays

After school in your own time zone, Eastern to Pacific.

Weekends

A steady weekly slot for families who prefer it.

1-on-1

Booked around the school calendar and exam weeks.

One teacher all term

The same person reads your code each week.

Your editor, shared

BlueJ, Eclipse, IntelliJ IDEA or VS Code.

Errors as lessons

We start from the message on your screen.

No homework answers

We teach the idea; the solution stays yours.

Any state

Live on video, wherever you study.

Batch or one to one

Fifteen to twenty learners, or just you.

Student work

Programs our students have built

Work from learners who once stared at the same compiler errors. More on the student labs page.

NutriLife AI nutrition coach project screenshot

AI and ML

NutriLife

An AI nutrition coach that reads what you eat and works you toward a target.

by Bhavya · Open it

Misti AI chatbot for maths and coding screenshot

AI and ML

Misti

A chatbot that answers mathematics and programming questions, built and deployed by a student.

by Harshit · Open it

GuardianX AI internet safety assistant screenshot

AI and ML

GuardianX

An assistant that helps a young person recognise unsafe situations online.

by Vivaan · Open it

SkyCast weather forecast application screenshot

Web app

SkyCast

A weather forecasting site with live conditions for any location.

by Krish

Fees

Fees

Java and every editor on this page cost nothing to download. What you pay for is the live teaching: a monthly fee shown in US dollars, no semester contract, and nothing owed if you stop when a month ends.

Free first class

USD 0

no card required

  • A free first lesson
  • Bring the file that will not compile
  • No card details
Book it

Group batch

USD 100

a month, billed in US dollars

  • Fifteen to twenty learners
  • A regular teacher
  • Choose your batch
  • Monthly
Start here

One to one

USD 150

a month, billed in US dollars

  • Just you and the teacher
  • Times that suit you
  • Built around your own course
Enquire

What families say

Rated 4.9 across 547 Google reviews

Parents and students in their own words, as posted on Google.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

Questions from students

Cannot find symbol: common questions

What does cannot find symbol mean in Java?

It means the compiler found a name (a variable, a method or a class) that it could not match to any declaration it can see from that line. The symbol line says which name and what kind it is; the location line says where Java searched.

How do I fix cannot find symbol?

Go to the first error, read the symbol line, and search your code for that exact word. Fix a spelling or capital letter if it differs, move a declaration up if it sits inside a block that has closed, and add an import for library classes such as ArrayList or Scanner. Compile again after each change.

Why does Java say cannot find symbol for a variable I declared?

Usually because the variable was declared inside a block, such as a loop or an if, and you used it after that block closed. A local variable only exists until the closing brace of the block it was declared in. Declare it before the block instead.

Why do I get cannot find symbol for ArrayList or Scanner?

Both live in the java.util package, which Java does not import automatically. Only java.lang and your own package are imported for you. Add import java.util.ArrayList; or import java.util.Scanner; above your class.

Is Java case sensitive?

Yes. Oracle's Java tutorial states that variable names are case-sensitive, so total and Total are two different names. A capital letter in the wrong place is one of the most common causes of this error.

What is the difference between cannot find symbol and identifier expected?

Cannot find symbol is about a name Java cannot match to a declaration. Identifier expected means Java wanted a name at a point where the grammar requires one, often because a statement such as an assignment or a println was written directly inside the class instead of inside a method.

What does Eclipse show instead of cannot find symbol?

Eclipse uses its own compiler, so the wording differs. In our tests the same mistakes appeared as messages such as Total cannot be resolved to a variable, ArrayList cannot be resolved to a type, and The method lenght() is undefined for the type String.

Will you fix my CodeHS or school Java assignment for me?

No. We do not provide answers or solutions to graded assignments. A teacher works through the error message with you and teaches the idea behind it, so you can fix your own code and explain it.

Does this error matter for the AP Computer Science A exam?

Indirectly. The exam is fully digital in College Board's Bluebook app, and the mistakes behind this error, especially mixing up length, length() and size() for arrays, String and ArrayList, are exactly the distinctions the course tests.

When are live Java classes for US students?

Weekdays or weekends, flexible. Choose your batch, or for a very personalised plan choose 1-on-1 at your convenience, weekend mornings or weekdays.

How much do the Java classes cost?

The first lesson is free. After that you pay one month at a time, and the monthly fee is shown in US dollars in the fees section of this page.

Elsewhere on this site

Related pages

More for US students learning Java.

Coding classes in the USA

Every page we have written for US families.

How to debug code

A method for any error in any language.

AP Computer Science A classes

Our live AP CSA preparation.

Java for beginners

Where a first Java course starts.

Java classes for teens

The teen Java track in detail.

AP CSP or AP CSA first?

Choosing between the two AP courses.

BlueJ not working: fixes

BlueJ not working? Official fixes for install, VM errors, output and frozen runs.

Eclipse Java help for students

Eclipse for Java students: install, run, read errors, fix Java version and memory.

IntelliJ and PyCharm free for students

IntelliJ IDEA and PyCharm for students: free core, student license, setup fixes.

Start here

Book a free first lesson

Send the error message you are stuck on, or just tell us which course you are taking. The teacher begins from your own code, so the first lesson is about the problem in front of you.

Curious how a lesson actually runs? How we teach describes one from start to finish, and the course pages list every syllabus.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Classes are taught live on video by teachers based in India, so there is no local center to visit. For US students, WhatsApp is the fastest way to reach us.

The first lesson is free and we never ask for payment details.

Want a class sooner? Book a priority demo

A priority demo is a full class of about 45 to 60 minutes. After the class the mentor sends a written skill report and a personal learning roadmap on WhatsApp. If you enrol, the demo fee is adjusted against your first month's fee. Share your demo Order ID with us on WhatsApp and we take it off.

Book a priority demo

Keep exploring Modern Age Coders

Related courses and guides

Learn more

Free resources

From the blog

Start here

Free classPriority demoCall us