简体   繁体   English

java:package org.apache.commons.math3.fraction 不存在

[英]java: package org.apache.commons.math3.fraction does not exist

I want to use the following package in java:我想在 java 中使用以下 package:

import org.apache.commons.math3.fraction.BigFraction;

To run this example:要运行此示例:

public class Test {
 
    public static void main(String[] args) {
        double[] n = {0.750000000, 0.518518000, 0.905405400, 0.142857143,
            3.141592654, 2.718281828, -0.423310825, 31.415926536};
 
        for (double d : n)
            System.out.printf("%-12s : %s%n", d, new BigFraction(d, 0.00000002D, 10000));
    }
}

but I get the following error:但我收到以下错误:

java: package org.apache.commons.math3.fraction does not exist

Are there any solutions to this?有什么解决办法吗?

And there is something specific in my case that differs from the other is that "commons" is highlighted in red and the rest is not.在我的情况下,与其他情况不同的是,“commons”以红色突出显示,而 rest 则没有。

Have you checked if the package is in the correct place in your file system?您是否检查过 package 是否在您的文件系统中的正确位置? If it is in the right place, the next place that could be an issue is in the import message.如果它在正确的位置,那么下一个可能出现问题的地方就是导入消息。 Make sure it is correct, and maybe try shortening it to org.apache.commons.math3.* if you want to cut down on the possible typos.确保它是正确的,如果你想减少可能的拼写错误,可以尝试将其缩短为 org.apache.commons.math3.*。

Given that you are using maven, just add the following dependency to your pom.xml and reload the project in your IDE:鉴于您使用的是 maven,只需将以下依赖项添加到您的pom.xml并在您的 IDE 中重新加载项目:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.6.1</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM