Java cannot access class, class file not found

Ahmad :

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.

Ahmad :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=448419&siteId=1