Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Won't recognize classes in same directory 1

Status
Not open for further replies.

tbuch

Programmer
Oct 17, 2000
80
US
I have a problem in my classroom. When trying to do labwork in class, I am unable to compile apps that call on other class files. It should be able to find them if they are in the same directory, but doesn't. Everything works fine in my office and at home, but not in the classroom or in the school's open lab.

Anyone have any suggestions?

tbuch
 
There may be a package mismatch. All the files should have the same package ????; line near the top of the file or none at all. Try javap -classpath . FileNameWithoutDotClass on each class file in the directory and see what package they are in.



 
That's not it, but thanks for the response. Let me give a little more detail.

In this exercise, I am having my students create a class, let's call it MyClass, and save it in the C:\java folder.

Next, they are to create an applet , we'll call it MyApplet, that instantiates a MyClass object. They are also saving MyApplet in the C:\java directory.

Next, they are to create their .html file, MyApplet.html, and save it in the same directory.

So now, we have two .java files and one .html file:
Code:
C:\java\MyClass.java
C:\java\MyApplet.java
C:\java\MyApplet.html
[\code]
Now, I should be able to compile MyApplet.java which, in turn, should compile MyClass.java. Key word... SHOULD! Since they are in the same directory, this should work fine with no package or import statements to call from MyClass. Instead, I get an error stating:
[code]
MyApplet.java:9: cannot resolve
symbol  : class MyClass
location: class MyApplet
                MyClass newClass = new MyClass();
                ^
MyApplet.java:9: cannot resolve
symbol  : class MyClass
location: class MyApplet
                MyClass newClass = new MyClass();
                                       ^
[\code]
Like I said, this works fine at home and in my office, but not in the classroom or in the open labs.

Any clues? I'm at my wits end!

tbuch
 
how about:

javac -classpath . MyApplet.java

or

javac -classpath . MyClass.java MyApplet.java
 
Thanks, Sean!

Your advice was right on the mark. Can you tell me why that would happen? Regardless of the classpath, I thought it would always look in the current directory.

tbuch
 
Can you tell me why that would happen? Regardless of the classpath, I thought it would always look in the current directory.

I'm pretty sure this changed in JDK 1.2 when they added sourcepath and the bootclasspath. See links below for more info.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top