Abhishek Sagar
Abhishek Sagar

Reputation: 1326

Symbol not found even when referenced class exist

I am very new to java. Can somebody help why I am getting error: cannot find symbol error.

I have a class User.java which I am able to compile with success. User.class gets created in the same dir.

When I try to compile Another class UserDao.java which used User, it reports cannot find symbol error as stated.

vm@vm:~/UserManagement/com/tutorialspoint$ pwd
/home/vm/UserManagement/com/tutorialspoint
vm@vm:~/UserManagement/com/tutorialspoint$ ls
User.class  UserDao.java  User.java  UserManagement.war  UserService.java  web.xml

vm@vm:~/UserManagement/com/tutorialspoint$ javac UserDao.java
UserDao.java:15: error: cannot find symbol
public List<User> getAllUsers(){
           ^
symbol:   class User
location: class UserDao

UserDao.java

package com.tutorialspoint;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class UserDao {
   public List<User> getAllUsers(){
   List<User> userList = null;
   try {

Please help.

Thanks.

Upvotes: 1

Views: 788

Answers (1)

Jorn Vernee
Jorn Vernee

Reputation: 33845

You did not set a classpath, which defaults to be the current directory. So javac can't find the .class file for User.

Please take the effort to read the classpath documentation.

The solution here is to either compile all classes at once:

javac UserDao.java  User.java UserService.java

Or set the classpath to the root of your packages:

javac -cp "/home/vm/UserManagement" UserDao.java

Upvotes: 1

Related Questions