Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help a 1st timer import library in NetBeans IDE

 
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 17654
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic