• 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

Package problem

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working through a book called Sun Certified Programmer & Developer for Java 2 by Kathy Sierra and Bert Bates(Osborne books). The chapter of the book that I am working on called Declarations and Modifiers(Exam Objective 1.2). The section that I am working on is called Public Members. The book example is:
package book;
import cert.*; // Import all classes in the cert package
class Goo {
public static void main(String [] args) {
Sludge o = new Sludge();
o.testIt();
}
}

second file:
package cert;
public class Sludge {
public void testIt() {
System.out.println("sludge");
}
Goo should be able to invoke the method in Sludge without problems because both the sludge class and its testIt () method are marked public.
But this the result:
Attempt to compile:
D:\j2sdk1.4.2_01\bin\cert\book>javac Goo.java
Goo.java:2: package cert does not exist
import cert.*; // Import all classes in the cert package
^
Goo.java:7: cannot resolve symbol
symbol : class Sludge
location: class book.Goo
Sludge o = new Sludge();
^
Goo.java:7: cannot resolve symbol
symbol : class Sludge
location: class book.Goo
Sludge o = new Sludge();
^
3 errors
D:\j2sdk1.4.2_01\bin\cert\book>
Where am I going wrong?
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set the CLASSPATH.
 
John Farrell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean dos path?
D:\j2sdk1.4.2_01\bin\cert\book> path
Path=D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;D:\j2sdk1.4.2_01\bin\;D:\
j2sdk1.4.2_01\bin\cert
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
 
John Farrell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a difference between setting the path and class path?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not your Path problem. You didn't set the pkg well.
first:
cert and book are different pkgs. you should not put book inside cert.
second: when you compile you should do it at D:\j2sdk1.4.2_01\bin> javac book/Goo.java and java book/Goo.
 
John Farrell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That works. Thanks.
Another question.
Is it possible to access the program Goo without specifying the directory book?
reply
    Bookmark Topic Watch Topic
  • New Topic