错误:无法访问包org.apache.commons [英] Error: The package org.apache.commons is not accessible

查看:303
本文介绍了错误:无法访问包org.apache.commons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才开始使用Eclipse,并且在尝试安装外部库时遇到问题.在完成在线教程之后,我将.jar文件添加到类路径中,并在引用的库文件夹中看到该文件.尽管如此,在尝试导入时,出现错误:

I have just recently started using Eclipse and am running into problems trying to install external libraries. Following online tutorials, I add the .jar file to the classpath and I see it in the referenced libraries folder. Despite this, when trying to import, I get the error:

无法访问org.apache.commons包

The package org.apache.commons is not accessible

作为参考,我正在尝试安装apache math commons库.

For reference, I am trying to install the apache math commons library.

推荐答案

您的代码可能有两个问题.

Your code probably has two issues.

首先,import语句是错误的,因为在Java中您无法添加包本身,但是包的所有类如下(请注意.*;):

First, the import statement is wrong since in Java you cannot add a package itself, but all classes of a package as follows (note .*; at the end):

import org.apache.commons.math4.linear.*;

或特定类别,例如

import org.apache.commons.math4.linear.FieldMatrix;

其次,您通过文件,可能没有必需的requires <module>;语句. JPMS是在Java 9中引入的,您拥有Java 12.

Second, you use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9 and you have Java 12.

执行以下操作之一:

  • 删除module-info.java文件(如果需要,可以通过右键单击项目文件夹并选择 Configure> Create module-info.java 来重新创建它)
  • module-info.java中添加相应的 requires语句,例如通过使用import语句并使用相应的 Quick Fix ( Ctrl + 1 )
  • Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
  • In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

这篇关于错误:无法访问包org.apache.commons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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