Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java cannot access class, class file not found

When I try to make a project in IntelliJ I receive the following error on this line:

Sentence sent = new Sentence();  sent.emptySegments(); 

Error:

Error:(151, 10) java: cannot access javax.xml.bind.RootElement class file for javax.xml.bind.RootElement not found 

Sentence is a class which implements the RootElement interface

import javax.xml.bind.RootElement; ... public class Sentence extends MarshallableRootElement implements RootElement   { 

All packages exist and I can jump to declaration of each interface or class but I don't know why IntellJ says it cannot access or find them? However RootElement is an interface and not a class

public interface RootElement extends Element {     void validate() throws StructureValidationException; } 

The above declaration is in a jar file named jaxb-rt-1.0-ea.jar and it exists in the Project librarians.

like image 735
Ahmad Avatar asked Jul 24 '16 07:07

Ahmad


People also ask

Where can I find .class file in Java?

class file in java is generated when you compile . java file using any Java compiler like Sun's javac which comes along with JDK installation and can be found in JAVA_HOME/bin directory.

How do I retrieve a Java class file?

In order to decompile class file, just open any of your Java projects and go to Maven dependencies of libraries to see the jar files included in your project. Just expand any jar file for which you don't have the source attached in Eclipse and click on the . class file.


2 Answers

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)

like image 173
Meena Chaudhary Avatar answered Sep 20 '22 02:09

Meena Chaudhary


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.
like image 31
Ahmad Avatar answered Sep 19 '22 02:09

Ahmad