Apache Commons Math ' SummaryStatistics cannot be resolved to a type '

1.8k views Asked by At

I am attempting to use Apache Commons Math 3.3 for a static data processing class, and am using Eclipse Mars to create it. I have successfully downloaded the bin and src files, and added them to the build path of my project; I can see them in my JRE System Library. I have also added the javadoc URL in the 'Javadoc Location' tab. I am successful in importing classes from the library.

However, when I attempt to instantiate an object from AC-M, Eclipse is unable to resolve that object as a type. For instance,

import org.apache.commons.math3.stat.descriptive.SummaryStatistics.*;

public class Stats {

public static double mean(double[] data) {
    SummaryStatistics curr = new SummaryStatistics();
    for (int a = 0; a < data.length; a++) {
        curr.addValue(data[a]);
    }
    double mn = curr.getMean();
    return mn;}

}

The import statement works fine. However, immediately Eclipse reads an error in my 4th line of code:

SummaryStatistics cannot be resolved to a type

This occurs for all other objects, e.g. PearsonsCorrelation, SimpleRegression, etc. (I successfully import the respective portions of the library for all objects.) Eclipse offers an option to 'Fix project setup..', yet upon clicking, no solutions are available. I have cleaned the buildpath to no avail. I would appreciate assistance in fixing this problem.

EDIT: I added the jar files by selecting the package of interest and clicking Properties>JRE System Library [jre8] Edit...>Installed JREs...>Edit...>Add External JARs...then adding commons-math3-3.3.jar to the library.

2

There are 2 answers

2
Joe On BEST ANSWER

This import:

import org.apache.commons.math3.stat.descriptive.SummaryStatistics.*;

doesn't import SummaryStatistics itself, just any classes defined within that class. Add:

import org.apache.commons.math3.stat.descriptive.SummaryStatistics;

as well.

0
botha On

It was caused by the fact that Eclipse environment was set not to build automatically (Project -> Build Automatically).

Even though I was adding a correct JARs (through Project - Properties - Java Build Path - Libraries), Eclipse did not rebuild, meaning it didn't recalculate new dependencies (and didn't apply them on the existing source).

https://www.eclipse.org/forums/index.php/t/67910/