0

I am trying to use the stdlib.jar file provided in the link below:

http://introcs.cs.princeton.edu/java/stdlib/

I am having a lot of problems however in using the classes within this jar file. I'm not sure how to access the classes within this jar file because the file is not saved within a specific package of java, its just saved in a location within my netbeans folder. I tried looking at the following question:

Import custom libraries in Java

but I'm not sure what was meant by "adding the classpath while running" as well. What I have tried so far is adding the jar file directly to my project through netbeans - which didn't work - and I have tried creating a library that contained this jar file and adding the library to the project, which also doesn't work.

What I mean by doesn't work is that I cannot any of the classes from the jar file in my source code since the class is not recognized. Here is my relevant source code:

package plotproject;


public class Histogram {

   private final double[] freq;   // freq[i] = # occurences of value i
   private double max;            // max frequency of any value

    // Create a new histogram. 
    public Histogram(int N) {
        freq = new double[N];
    }

    // Add one occurrence of the value i. 
    public void addDataPoint(int i) {
        freq[i]++; 
        if (freq[i] > max) max = freq[i]; 
    } 

    // draw (and scale) the histogram.
    public void draw() {
        StdOut.println("Hello"); //shows error in netbeans "cannot find symbol StdOut
        StdDraw.setYscale(0, max); //shows error in netbeans "cannot find symbol StdDraw
        StdStats.plotBars(freq);//shows error in netbeans "cannot find symbol StdStats
    }
}

How can I get the classes from the jar file to be used in my source code? Also, I already looked at the question Java, How to add library files in netbeans? before asking this, but I have already added the library to my project, so why is not being accessed in the source code?

Community
  • 1
  • 1
Jeremy Fisher
  • 1,744
  • 2
  • 21
  • 46
  • How is this a duplicate of that question? I mentioned explicitly that I tried that method in the question... – Jeremy Fisher Jun 09 '14 at 15:51
  • 1
    I had the same problem with these jars from Princeton and I was able to solve it using the NetBeans "Java Free-Form Project". I could answer the question if you ask it again in new format - there is not enough space in comments for that – HEKTO Jun 09 '14 at 16:48
  • Thanks for your help. Do you mean ask a new question entirely? – Jeremy Fisher Jun 09 '14 at 16:49
  • Yes, in some form... The moderator thinks the question has been answered, I don't know why - I won't dig into that. But - I can just explain what I did. – HEKTO Jun 09 '14 at 16:52
  • I'll try but I hope the mods don't close it down again for apparently being a duplicate. – Jeremy Fisher Jun 09 '14 at 16:54
  • Well I can't post for another 90 minutes so once the question goes up I'll put a link here. Thanks again for your help – Jeremy Fisher Jun 09 '14 at 17:03
  • Oh, I looked at your source more - you have used `package` in the beginning of your program. The moderator was right - this won't work with regular jars from Princeton. You need "packaged" versions (which I didn't use myself) – HEKTO Jun 09 '14 at 17:05
  • 2
    http://introcs.cs.princeton.edu/java/stdlib/ - look at Q + A in the end. – HEKTO Jun 09 '14 at 17:08
  • Works, thank you so much – Jeremy Fisher Jun 09 '14 at 17:16

0 Answers0