简体   繁体   English

Apache Commons Math'SummaryStatistics无法解析为类型'

[英]Apache Commons Math ' SummaryStatistics cannot be resolved to a type '

I am attempting to use Apache Commons Math 3.3 for a static data processing class, and am using Eclipse Mars to create it. 我正在尝试将Apache Commons Math 3.3用于静态数据处理类,并正在使用Eclipse Mars创建它。 I have successfully downloaded the bin and src files, and added them to the build path of my project; 我已经成功下载了bin和src文件,并将它们添加到我的项目的构建路径中; I can see them in my JRE System Library. 我可以在我的JRE系统库中看到它们。 I have also added the javadoc URL in the 'Javadoc Location' tab. 我还在“ Javadoc位置”标签中添加了Javadoc URL。 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. 但是,当我尝试从AC-M实例化一个对象时,Eclipse无法将该对象解析为一种类型。 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: 但是,Eclipse立即在我的第四行代码中读取了一个错误:

SummaryStatistics cannot be resolved to a type 摘要统计无法解析为类型

This occurs for all other objects, eg 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. 所有其他对象(例如PearsonsCorrelationSimpleRegression等) PearsonsCorrelation发生这种情况(我成功导入了所有对象的库的相应部分。)Eclipse提供了“修复项目设置..”的选项,但是单击后,没有可用的解决方案。 。 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. 编辑:我通过选择所需的包并单击Properties> JRE System Library [jre8] Edit ...> Installed JREs >> Edit ...> Add External JARs,然后添加commons-math3添加了jar文件。 -3.3.jar到库。

This import: 此导入:

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

doesn't import SummaryStatistics itself, just any classes defined within that class. 不会导入SummaryStatistics本身,而不会导入该类中定义的任何类。 Add: 加:

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

as well. 也一样

It was caused by the fact that Eclipse environment was set not to build automatically (Project -> Build Automatically). 这是由于Eclipse环境设置为不自动构建(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). 即使我添加了正确的JAR(通过Project-Properties-Java Build Path-Libraries),Eclipse也没有重建,这意味着它没有重新计算新的依赖关系(也没有将它们应用于现有的源代码)。

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

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

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