Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help a 1st timer import library in NetBeans IDE  RSS feed

 
Stan Austin
Ranch Hand
Posts: 50
1
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Hopefully this can be answered easily enough.
Last Thursday I was introduced to libraries, namely stdlib, of; http://introcs.cs.princeton.edu/java/stdlib/
I downloaded, StdIn.java and StdOut.java, to the folder I was writing the program in. (this was using ubuntu OS, and the terminal)
Then compiled to get the .class file, and I don't think I had to write import or anything in my program.
I am now trying to do this at home on Win10 OS, using NetBeans IDE,
I have downloaded the library (its in my Downloads folder)
Then right clicked on the libraries tab under the program name, add library, create, created library called "StdLib", added the jar file (added it both to class path and sources)

Then i have written the following code


also tried (import stdlib.jar & import Std.Lib)

but i get a error messages such as

or


Any help greatly appreciated, TIN
 
Junilu Lacar
Sheriff
Posts: 10926
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the right way to specify your import statement.  It looks like those classes don't have package declarations and as such they will be in the default package. To use these classes, your program needs to be in the default package as well; that is, you can't put any package declaration statement in your program.  If you do that, you won't have to specify any import statements for those classes; you just use them directly from your program.
 
Knute Snortum
Sheriff
Posts: 3734
90
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use the standard jar file to import as it has its class files in the default package.  You need this jar file that has the class files in the package edu.princeton.cs.introcs.  Download it and move it to some location where you'll know where it is.  I usually put it in a folder called lib just under my project folder -- the same folder that has src.  In NetBeans, right-click on the Libraries node in the project window and click Add JAR/Folder.  Search for the jar file and press Open.  Your jar file should appear in the projects window.  Press F5 if it doesn't.  Now you should be able to do this:
 
Stan Austin
Ranch Hand
Posts: 50
1
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You can't use the standard jar file to import as it has its class files in the default package.  You need this jar file that has the class files in the package edu.princeton.cs.introcs.  Download it and move it to some location where you'll know where it is.  I usually put it in a folder called lib just under my project folder -- the same folder that has src.  In NetBeans, right-click on the Libraries node in the project window and click Add JAR/Folder.  Search for the jar file and press Open.  Your jar file should appear in the projects window.  Press F5 if it doesn't.  Now you should be able to do this:

Sweet thank you, for the link and instructions.
I couldnt get Junilu's method to work, but this did the trick.
A little bit annoying that its not just called import stldlib-package.StdIn, that would be much more user friendly lol.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!