简体   繁体   中英

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

I want to use the following package in java:

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.

Have you checked if the package is in the correct place in your file system? 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.

Given that you are using maven, just add the following dependency to your pom.xml and reload the project in your IDE:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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