JCFS / JAVA / 01
Java for teens
From first class to objects and lists.
Open the syllabusUnited States · High school and college · Java compiler errors
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
Each one is live, and each one starts from the code your student is writing right now.

JCFS / 01
Ages 13 to 18. Variables, methods, classes and the habit of reading errors.
Open the syllabus →
JCFS / 02
The four units, the Java Quick Reference and timed free-response practice.
Open the syllabus →
JCFS / 03
Core Java for intro CS courses, then on to larger programs.
Open the syllabus →Reading the message
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.
// 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.
> 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 errorsOur run, javac 22.0.1 on Windows 11, 17 October 2026. Two separate errors, one per unmatched name.
| Part | In our run | What it tells you |
|---|---|---|
| File and line | Grades.java:8 | Open that file and go to that line first. The mistake is almost always on it or just above it. |
| Error name | error: cannot find symbol | The compiler hit a word it could not connect to anything declared. Nothing was run yet. |
| Caret | The ^ under score | The exact word the compiler choked on, not the start of the line. |
| symbol: | variable score | What kind of name Java expected: variable, method (with argument types), or class. |
| location: | class Grades | Where Java was searching. For a member it reads, for example, variable s of type String. |
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.
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
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 we got | The fix |
|---|---|---|
| 1. Wrong capital letter | variable Total | Java treats total and Total as different names. Match the declaration exactly. |
| 2. Variable used outside its block | variable score | Declare it before the block that changes it, so it still exists afterwards. |
| 3. Loop counter used after the loop | variable k | A counter declared in the for header ends with the loop. Keep a separate variable if you need the value later. |
| 4. Missing import | class ArrayList | Add import java.util.ArrayList; above the class. The same goes for Scanner and Random. |
| 5. Misspelled method | method lenght() | Check the spelling against the documentation or the Java Quick Reference. |
| 6. Method or field that does not exist on that type | variable length (on a String) | Strings use length() with brackets; arrays use .length without; an ArrayList uses size(). |
| 7. Method you never wrote | method printReport(int[]) | Write the method, or fix the call so its name and argument types match one you wrote. |
| 8. Class the compiler cannot see | class Student | Put Student.java in the same project folder or package, and compile it too. |
// 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 Arrays1Ours: 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.
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.
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
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.
// 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
1Ours, 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.
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.
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
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.
| Mistake | javac says | Eclipse compiler says |
|---|---|---|
| Wrong capital letter | cannot find symbol, symbol: variable Total | Total cannot be resolved to a variable |
| Missing import | cannot find symbol, symbol: class ArrayList | ArrayList cannot be resolved to a type |
| Misspelled method | cannot find symbol, symbol: method lenght() | The method lenght() is undefined for the type String |
| length() on an array | cannot find symbol, symbol: method length() | Cannot invoke length() on the array type int[] |
| Class not in the project | cannot find symbol, symbol: class Student | Student cannot be resolved to a type |
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.
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
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.
// 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.
| cannot find symbol | identifier expected | |
|---|---|---|
| What went wrong | A name is used that Java cannot match to a declaration | Java expected a name at a point where the grammar needs one |
| Typical cause | Typo, scope, missing import | A statement placed directly in the class body, or a missing bracket |
| Where to look | The declaration of the word under the caret | The braces around the line: is it inside a method? |
| First fix to try | Match spelling and capitals | Move the statement into main or another method |
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.
| Point | What College Board says |
|---|---|
| Format | “This is a fully digital exam.” Students answer in the Bluebook testing app. |
| Reference sheet | The Java Quick Reference “lists the accessible methods from the Java library that may be included on the exam”. |
| Free response | Section II: 4 questions in 1 hour 30 minutes. Question 3 works with an ArrayList, Question 4 with a 2D array. |
| Biggest unit | Unit 4, Data Collections, carries 30% to 40% of the multiple-choice weighting. |
| 2027 date | May 12, 2027, as listed on the AP Central exam page. |
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.
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
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.
| Line of code | symbol: 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 import | class 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
Where most students are when they first search for this error, and where practice takes them.
| Stage | What it looks like |
|---|---|
| 1. Alarmed | Sees a wall of red text and starts changing lines at random |
| 2. Locating | Goes to the file and line number, finds the word under the caret |
| 3. Diagnosing | Reads the symbol and location lines and names the cause |
| 4. Preventing | Declares variables in the right place and rarely sees the error at all |
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.
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 live courses chosen for students who write Java at school now, or who are about to.
JCFS / JAVA / 01
From first class to objects and lists.
Open the syllabusJCFS / JAVA / 02
The College Board course, unit by unit.
Open the syllabusJCFS / JAVA / 03
Logic and data structures behind the code.
Open the syllabusJCFS / NEXT / 01
The wider course, with the Create task.
Open the syllabusJCFS / NEXT / 02
A second language with friendlier errors.
Open the syllabusJCFS / NEXT / 03
Save every working version of your code.
Open the syllabusJCFS / PRO / 01
Intro CS Java, then real applications.
Open the syllabusJCFS / PRO / 02
The course after the intro sequence.
Open the syllabusJCFS / PRO / 03
USACO-style problems in Java or C++.
Open the syllabusHow lessons run
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.
The same person reads your code each week.
BlueJ, Eclipse, IntelliJ IDEA or VS Code.
We start from the message on your screen.
We teach the idea; the solution stays yours.
Live on video, wherever you study.
Fifteen to twenty learners, or just you.
Student work
Work from learners who once stared at the same compiler errors. More on the student labs page.

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

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

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

Web app
A weather forecasting site with live conditions for any location.
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
Group batch
USD 100
a month, billed in US dollars
One to one
USD 150
a month, billed in US dollars
What families say
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
Weekdays or weekends, flexible. Choose your batch, or for a very personalised plan choose 1-on-1 at your convenience, weekend mornings or weekdays.
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
More for US students learning Java.
Every page we have written for US families.
A method for any error in any language.
Our live AP CSA preparation.
Where a first Java course starts.
The teen Java track in detail.
Choosing between the two AP courses.
BlueJ not working? Official fixes for install, VM errors, output and frozen runs.
Eclipse for Java students: install, run, read errors, fix Java version and memory.
IntelliJ IDEA and PyCharm for students: free core, student license, setup fixes.
Start here
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.
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