JAVAWarningSyntax ErrorApril 30, 2026

Syntax Error

Cannot find symbol: method add(int, Person) in class com.example.Person

What This Error Means

This error occurs when the Java compiler cannot find a method or field that is supposed to exist in a class. This is often due to a simple typo or incorrect method name.

Why It Happens

In this case, the error is caused by trying to call a method named 'add' with parameters 'int' and 'Person' on a class named 'Person'. However, the actual method name might be 'addPerson' or 'addPersonWithId'. The Java compiler is unable to find a method that matches the name and parameters specified.

How to Fix It

  1. 1To fix this error, check the method name and parameters in the code and make sure they match the actual method name and parameters. Here's a step-by-step guide:
  2. 21. Review the class definition of 'Person' and look for the method that matches the name and parameters.
  3. 32. If you find the correct method, check if you have imported the correct class.
  4. 43. If the method does not exist, create the method with the correct name and parameters.
  5. 5// Before (broken code)
  6. 6public class Main {
  7. 7 public static void main(String[] args) {
  8. 8 Person person = new Person();
  9. 9 person.add(1, new Person());
  10. 10 }
  11. 11}
  12. 12// After (fixed code)
  13. 13public class Main {
  14. 14 public static void main(String[] args) {
  15. 15 Person person = new Person();
  16. 16 person.addPerson(1, new Person());
  17. 17 }
  18. 18}

Example Code Solution

❌ Before (problematic code)
Java
public class Person {
  public void add(int id, Person person) {} // This method does not exist
}
✅ After (fixed code)
Java
public class Person {
  public void addPerson(int id, Person person) {}
}

Fix for Cannot find symbol: method add(int, Person) in class com.example.Person

Related JAVA Errors

Related JAVA Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error