Apache的百科全书:ClassNotFoundException异常 [英] apache commons: ClassNotFoundException

查看:193
本文介绍了Apache的百科全书:ClassNotFoundException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 EnumeratedIntegerDistribution() org.apache.commons.math3.distribution 来benefite ,如下所示。

I'm trying to benefite from the EnumeratedIntegerDistribution() from org.apache.commons.math3.distribution, as shown below.

我在室内用工作JDK7,在Windows XP,从命令行运行,在一个只有项目文件夹

I'm working wiht jdk7 , on windows Xp, running from Command Line, in one and only project folder

我做的:


  • 下载Commons-math3-3.2并解包到我的文件夹,我的是java的。

  • 编译我的源与(没有错误没有警告)
        的javac -cp公地math3-3.2 /公地math3-3.2.jar CheckMe.java

  • 运行的Java CheckMe

进口java.lang.Math中的*。
进口org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;

import java.lang.Math.*; import org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;

公共类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();  
} 

}

不过我有:

ClassNotFoundException的:org.apache.commons.math3.distribution.EnumeratedIntegerDistribution
在18行 - 呼吁EnumeratedIntegerDistribution()

ClassNotFoundException: org.apache.commons.math3.distribution.EnumeratedIntegerDistribution at line 18 - the call for EnumeratedIntegerDistribution()

如果我跑,我只是建议(下):

If I run as I was just advised (below):

    java -cp   commons-math3-3.2/commons-math3-3.2.jar  CheckMe

我得到错误:无法找到的原则类CheckMe

I get error: impossible to find the principle class CheckMe

感谢很多提前为您的意见。

Thanks a lot in advance for your advise.

推荐答案

您需要指定类路径既当您编译,并在运行。因此运行

You need to specify the classpath both when you compile and when you run. So running

java CheckMe.java 

是不够的。还应当

is not enough. Also it should be

java CheckMe

假设类 CheckMe 不在任何包。

您需要执行

java -cp commons-math3-3.2/commons-math3-3.2.jar CheckMe

指定罐子和其他类的 CheckMe 程序的需求。

这篇关于Apache的百科全书:ClassNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆