Missing Import Errors in Java
Java's cannot find symbol or package does not exist errors mean the compiler can't locate a class. This is either a missing import statement or a missing dependency.
Add the Import
// Error: cannot find symbol: variable List
// Fix:
import java.util.List;
import java.util.ArrayList;
List<String> items = new ArrayList<>();Missing Maven Dependency
<!-- pom.xml -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>mvn clean installMissing Gradle Dependency
// build.gradle
implementation 'com.google.code.gson:gson:2.10.1'gradle build --refresh-dependenciesStatic Imports
For static methods and constants:
// Instead of: Assert.assertEquals(...)
import static org.junit.jupiter.api.Assertions.assertEquals;
assertEquals(expected, actual);
// For constants
import static java.lang.Math.PI;
double area = PI * r * r;Common Confusions
// java.util.Date vs java.sql.Date
import java.util.Date; // Most of the time you want this
// Jakarta EE vs javax (Jakarta EE 9+)
// Old: import javax.servlet.http.HttpServletRequest;
// New: import jakarta.servlet.http.HttpServletRequest;IDE Auto-Import
IntelliJ: Alt+Enter on the unresolved symbol.
VS Code: Ctrl+. with the Java extension.
Bugsly captures ClassNotFoundException and NoClassDefFoundError at runtime, which indicates imports that resolved at compile time but are missing from the runtime classpath.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
How to Fix Referenceerror in Laravel When Deploying
Learn how to diagnose and fix the referenceerror in Laravel when deploying. Includes code examples and prevention tips.
Read moreHow to Fix Xss Vulnerability in Ruby
Learn how to diagnose and fix Xss Vulnerability errors in Ruby. Step-by-step guide with code examples.
Read moreHow to Fix Xss Vulnerability in Java
Fix Xss Vulnerability in your Java app. Understand the root cause and apply the right solution.
Read moreFix BigInt Error in Vue
Learn how to fix the BigInt error in Vue. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read more