import not finding class in java

Tawnos

2[H]4U
Joined
Sep 9, 2001
Messages
3,808
For my project I need to import Queue.* from a jar provided by professor. Queue.jar is in the same directory as the file trying to import it, it is both in the windows classpath (2k) and mounted in netbeans. When I try
Code:
import mycs1.*;
import java.io.*;
import java.util.*;
import Queue.*;
mycs1 works (one of the files I need to import, also in classpath and mounted in netbeans) both from command line "javac GraphDriver.java" and from compile in NB.

However, Queue returns:
Project03/Graph.java [6:1] package Queue does not exist
import Queue.*;

This obviously causes lots of other havoc when I try to use Queue later ;).

running "jar -tvf Queue.jar" returns (cygwin, hence the bash shell)
Code:
$ jar -tvf Queue.jar
     0 Mon Jul 19 07:24:20 PDT 2004 META-INF/
    68 Mon Jul 19 07:24:20 PDT 2004 META-INF/MANIFEST.MF
   153 Mon Jul 19 07:24:14 PDT 2004 LinkedList$1.class
   288 Mon Jul 19 07:24:14 PDT 2004 LinkedList$Error.class
  1150 Mon Jul 19 07:24:14 PDT 2004 LinkedList$Itr.class
  1432 Mon Jul 19 07:24:14 PDT 2004 LinkedList$Node.class
  3959 Mon Jul 19 07:24:14 PDT 2004 LinkedList.class
   138 Mon Jul 19 07:24:14 PDT 2004 Queue$1.class
   273 Mon Jul 19 07:24:14 PDT 2004 Queue$Error.class
  1019 Mon Jul 19 07:24:14 PDT 2004 Queue$Itr.class
  2289 Mon Jul 19 07:24:14 PDT 2004 Queue.class
So I see that Queue.class is there.

The only difference I see is that in mycs1 (the working file), "jar -tvf mycs1.jar" returns
Code:
$ jar -tvf mycs1.jar
     0 Fri Jul 26 10:05:36 PDT 2002 META-INF/
    68 Fri Jul 26 10:05:36 PDT 2002 META-INF/MANIFEST.MF
  4215 Fri Sep 03 06:25:36 PDT 2004 mycs1/Keyboard.class
   288 Tue Sep 07 07:40:06 PDT 2004 mycs1/TextIO$Error.class
  6914 Tue Sep 07 07:40:08 PDT 2004 mycs1/TextIO.class
  1144 Fri Aug 02 14:59:48 PDT 2002 mycs1/Prompt.class
  3378 Sat Jul 27 10:21:38 PDT 2002 mycs1/IntArray.class
   297 Thu May 22 06:45:26 PDT 2003 mycs1/MyReflect$Error.class
  4926 Thu May 22 06:45:26 PDT 2003 mycs1/MyReflect.class
   153 Fri Sep 24 06:14:22 PDT 2004 mycs1/Module$1.class
   426 Fri Sep 24 06:14:22 PDT 2004 mycs1/Module$Error.class
  3584 Fri Sep 24 06:14:22 PDT 2004 mycs1/Module$Token.class
 18967 Fri Sep 24 06:14:22 PDT 2004 mycs1/Module.class
  9471 Tue Sep 21 03:08:26 PDT 2004 mycs1/Grader.class
since everything is within a folder within mycs1.

Can anybody offer any suggestions? and while you're thinking about it, mind telling me how to fix the "class has wrong version, 49.0 should be 48.0" because I upgraded to jdk 1.5? Netbeans 4 doesn't have that issue, but netbeans 4 also has a horrible interface and design ideas, whoever decided to cripple it as it is should be shot (just my opinion, of course).
 
Oh yes, and if I try to put the files of Queue into a subdirectory, it "finds them" but returns:
Code:
Project03/Graph.java [131:1] cannot access Queue.Queue
bad class file: C:\Documents and Settings\Tawnos\My Documents\java\Project03\Queue.jar(Queue/Queue.class)
class file contains wrong class: Queue
Please remove or make sure it appears in the correct subdirectory of the classpath.
      Queue cue = new Queue();
      ^
1 error
Errors compiling Graph.
 
well, I ended up unpacking everything from the jar and it's working afaik...stupid, but working, guess I'll have to take that
 
Put Queue.jar somewhere directly in the classpath (eg in the same folder as Project03). It needs to be in the root of the directory structure or another folder referred to in the classpath so that the compiler doesn't get all confoozled by the structure.

I'm not sure how to do it in NetBeans, but it's blindingly simple in Eclipse, so it shouldn't be too difficult.
 
Just on the top of my head, but writing "import Queue.*;" means you are importing an entire pakage; or folder. But in the case of the Queue.jar there is no such folder. So wouldn't writing "import Queue;" be the solution?
 
Nemezer said:
Just on the top of my head, but writing "import Queue.*;" means you are importing an entire pakage; or folder. But in the case of the Queue.jar there is no such folder. So wouldn't writing "import Queue;" be the solution?
Bingo. Had I read the contents of the actual file, it would've been obvious - you don't have a package called Queue - just the individual objects themselves. However, the classes in that folder won't have a package declaration (or at least, not the same as the folder you're in), so I'm not sure whether that would work or not. It might be an idea to extract the classes from the .jar (you can do this using WinRAR if you fancy doing it using a GUI), and look at the source.
 
For clarification, I tried all the advice here before extracting (classpath, import Queue, root dir, etc). I also tried it in eclipse. My thought is that, because Queue didn't have a fully qualified name, it wouldn't know which Queue to get. Once I extracted it it was easy enough to just create Queue objects directly from the class, but my directory is a bit more cluttered now ;).
 
Back
Top