包org.apache.commons不存在 [英] package org.apache.commons does not exist
问题描述
我喜欢使用 EnumeratedIntegerDistribution()
从 org.apache.commons.math3.distribution
,以得到离散概率分布
I'd love to use EnumeratedIntegerDistribution()
from org.apache.commons.math3.distribution
, to get discrete probabilities distribution
int[] nums_to_generate = new int[] { -1, 1, 0 };
double[] discrete_probabilities = new double[] { 0.4, 0.4, 0.2 };
我在室内用工作JDK7,在Windows XP,从命令行运行
I'm working wiht jdk7 , on windows Xp, running from Command Line
我做的:
-
添加到我的源文件
add to my source file
import org.apache.commons.math3;
编译我的类路径来源:(或)
compile my source with the classpath: (either)
javac -cp ./commons-math3-3.2/commons-math3-3.2.jar:. ConflictsAnimation.java
javac -cp commons-math3-3.2/commons-math3-3.2.jar ConflictsAnimation.java
不过我有一个神秘的
"error: package org.apache.commons does not exist"
谁知道会发生什么?我真的需要帮助。
Who knows what happens ? I really need a help.
请注意:
编译(并运行)是不正常类路径和不
阿帕奇的进口和调用numeratedIntegerDistribution()。
compilation (and run) is OK without the classpath and without the import of "apache" and call to numeratedIntegerDistribution().
与编译类路径,并没有appacheS给予
废话错误。
compilation with the classpath and without the "appache"s give nonsense errors.
感谢很多提前为你的伟大技能,程序员!
Thanks a lot in advance for your great skills, the programmers!
进口java.lang.Math中的*。
进口org.apache.commons.math3;
import java.lang.Math.*; import org.apache.commons.math3;
公共类CheckMe {
public class CheckMe {
public CheckMe() {
System.out.println("let us check it out");
System.out.println(generate_rand_distribution (10));
}
private static int[] generate_rand_distribution (int count){
int[] nums_to_generate = new int[] { -1, 1, 0 };
double[] discrete_probabilities = new double[] { 0.4, 0.4, 0.2 };
int[] samples = null;
EnumeratedIntegerDistribution distribution =
new EnumeratedIntegerDistribution(nums_to_generate, discrete_probabilities);
samples = distribution.sample (count);
return (samples);
}
public static void main (String args[]) {
System.out.println("Main: ");
CheckMe animation = new CheckMe();
}
}
推荐答案
这就是问题所在:
import org.apache.commons.math3;
这是试图导入的包的 - 你不能做到这一点。你必须要么使用通配符输入:
That's trying to import a package - you can't do that. You have to either use a wildcard import:
import org.apache.commons.math3.*;
或导入特定类型:
import org.apache.commons.math3.SomeTypeHere;
在你的情况下,它听起来像你真正想要的:
In your case it sounds like you actually want:
import org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;
我试过用样品类的只是的是进口和来自Apache下载jar文件,它工作正常。
I've tried a sample class with just that import and the jar file downloaded from Apache, and it works fine.
这篇关于包org.apache.commons不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!