Java cannot access class, class file not found

File -> Invalidate Caches/ Restart this worked for my after long hours of effectiveless


Try this

  1. Go to File
  2. Invalidate Caches/Restart
  3. You can choose only Invalidate and restart

(See Invalidate caches on IntelliJ's manual)


The project contained several modules. While the library was added to the project libraries, some modules lacked it in their dependency part. So I solved the problem using the following steps in IntelliJ

Creating a module library and adding it to the module dependencies:

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click + (on the top right) and select Jars or directories.
  6. In the dialog that opens, select the necessary files and folders. These may be individual .class and .java files, directories and archives
    (.jar and .zip) containing such files as well as directories with
    Java native libraries (.dll, .so or .jnilib).
  7. Click OK. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.

Rebuilding project worked for me.