Java无法访问类,找不到类文件 [英] Java cannot access class, class file not found

查看:2893
本文介绍了Java无法访问类,找不到类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在IntelliJ中创建项目时,我在此行收到以下错误:

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

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

错误:

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

句子是一个实现 RootElement 界面

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

所有包存在,我可以跳转到每个接口或类的声明,但我不知道为什么IntellJ说它无法访问或找到它们?但是 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;
}

以上声明位于名为 jaxb的jar文件中-rt-1.0-ea.jar 并且它存在于项目图书馆员中。

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

推荐答案

项目包含几个模块。虽然库已添加到项目库中,但某些模块在其依赖项部分中缺少它。所以我使用IntelliJ中的以下步骤解决了这个问题

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. 打开项目结构对话框(例如Ctrl + Shift + Alt + S)。

  2. 在对话框的左侧窗格中,选择模块。

  3. 在右侧窗格中,选择您感兴趣的模块。

  4. 在对话框的右侧,在模块页面上,选择依赖关系选项卡。

  5. 在依赖关系选项卡上,单击+(右上角),然后选择Jars或目录。

  6. 在打开的对话框中,选择所需的文件和文件夹。这些可能
    是单独的.class和.java文件,目录和存档

    (.jar和.zip)包含这些文件以及带有
    Java目录的目录(.dll,.so或.jnilib)。

  7. 单击确定。如有必要,请选择导出选项并更改依赖关系范围。

  8. 在项目结构对话框中单击确定。

  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.

这篇关于Java无法访问类,找不到类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆