• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package problem

 
John Farrell
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you set the CLASSPATH.
 
John Farrell
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a difference between setting the path and class path?
 
Karen Liu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That works. Thanks.
Another question.
Is it possible to access the program Goo without specifying the directory book?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic