Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package org.apache.commons does not exist

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  };

I'm working wiht jdk7 , on windows Xp, running from Command Line

I do:

  • add to my source file

    import org.apache.commons.math3; 
    
  • download commons-math3-3.2 and unpackage it to my current folder
  • 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
    

Still I've got a mysterious

    "error: package org.apache.commons does not exist"

Who knows what happens ? I really need a help.

Note:

compilation (and run) is OK without the classpath and without the import of "apache" and call to numeratedIntegerDistribution().

compilation with the classpath and without the "appache"s give nonsense errors.

Thanks a lot in advance for your great skills, the programmers!


Here is short demonstration:

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

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();  
    } 
}
like image 568
Galia Avatar asked Dec 30 '13 17:12

Galia


1 Answers

This is the problem:

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.*;

or import a specific type:

import org.apache.commons.math3.SomeTypeHere;

In your case it sounds like you actually want:

import org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;

I've tried a sample class with just that import and the jar file downloaded from Apache, and it works fine.

like image 111
Jon Skeet Avatar answered Sep 23 '22 18:09

Jon Skeet