The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Importing Packages

Posted by Wilma on September 28, 2001 at 7:35 AM

I�m new to Java programming and have no C++
background. I'm having real trouble with packages and
was wondering if anybody could help me. This
is an example I�m working with from the book: "Thinking in Java" by Bruce Eckel

I created 2 classes named Vector and List who are both
part of the com.bruceeckel.Util package:

package com.bruceeckel.Util;

public class Vector
{
public Vector()
{
System.out.println("com.bruceeckel.util.Vector");
}
}

package com.bruceeckel.Util;

public class List
{
public List()
{
System.out.println("com.bruceeckel.util.list");
}
}

I saved them both on c:\JavaOef\com\bruceeckel\Util as
Vector.java and List.java. I compiled them and there
was no problem. (It created the *.class files)

Then I created this class that is in a different
package (c05). This class will use the other two to
compile and then � hopefully � run:

package c05;
import com.bruceeckel.Util.*;

public class LibTest
{
public static void main(String args[])
{
Vector v = new Vector();
List L = new List();
}
}

I saved this class on c:\JavaOef\c05 as LibTest.java

When I try to compile this class I get the following
errors:

LibTest.java:2: package com.bruceeckel.Util does not
exist
import com.bruceeckel.Util.*;
^
LibTest.java:8: cannot resolve symbol
symbol : class Vector
location: class c05.LibTest
Vector v = new Vector();
^
LibTest.java:8: cannot resolve symbol
symbol : class Vector
location: class c05.LibTest
Vector v = new Vector();
^
LibTest.java:9: cannot resolve symbol
symbol : class List
location: class c05.LibTest
List L = new List();
^
LibTest.java:9: cannot resolve symbol
symbol : class List
location: class c05.LibTest
List L = new List();
^
5 errors

I suspect that there is a problem with my saving -
one book I have talks about a CLASSPATH, but how does
that work. I�ve tried to import the package, but I
still get errors.

Please, if you could help me, I would appreciate it
very much.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us