Java cannot access the class, class file not found

When I try to make a project in IntelliJ, I get 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 that implements the RootElement interface RootElement

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

All packages exist, and I can move on to declaring each interface or class, but I don’t know why IntellJ says that it cannot get or find them? However, RootElement is an interface, not a class.

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

The above declaration is in the jar file named jaxb-rt-1.0-ea.jar and exists in the project libraries.

+5
source share
1 answer

The project contains several modules. Although the library was added to the project libraries, some modules lacked it in terms of dependency. So I solved the problem by following these steps in IntelliJ

Creating a module library and adding it depending on the module:

  • Open the Project Structure dialog box (for example, Ctrl + Shift + Alt + S).
  • In the left pane of the dialog box, select "Modules."
  • In the right pane, select the module of interest.
  • On the right side of the dialog box on the Module page, select the Dependencies tab.
  • On the Dependencies tab, click + (top right) and select Mailboxes or Directories.
  • In the dialog box that opens, select the necessary files and folders. They can be separate .class and .java files, directories and archives
    (.jar and .zip) containing such files as well as directories using the Java Native Libraries (.dll, .so or .jnilib).
  • Click OK. If necessary, select the Export option and change the dependency area.
  • Click OK in the Project Structure dialog box.
+6
source

All Articles