Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

Bad class file

Thread view: 
PageV - 20 May 2004 16:12 GMT
I get
DoubleArr.java:11: cannot access Arrays2

bad class file: .\Arrays2.java

file does not contain class Arrays2

Please remove or make sure it appears in the correct subdirectory of the
classpath.

    Arrays2.fill(d, new Arrays2.RandDoubleGenerator());

The program is
import com.bruceeckel.util.*;

public class DoubleArr
{
public static void main(String args[])
{
    double[] d = new double[10];
    Arrays2.fill(d, new Arrays2.RandDoubleGenerator());
    Arrays2.print(d);

}
}
It works if I rename Arrays2.java to something else.  Why is the compiler
looking at a java file instead of a class file?  Am I supposed to put the
java files in the same directory as the class files?  This is what I had to
do with previous programs to avoid this error.  I would rather leave the
java files in the top directory and let the compiler create the directories
for the class files.

Ralph
Ryan Stewart - 21 May 2004 00:29 GMT
> I get
> DoubleArr.java:11: cannot access Arrays2
[quoted text clipped - 29 lines]
>
> Ralph

The .java file has to be within the correct directory structure, defined by
its package, for compilation. It does *not* have to be in the exact same
directory as the .class file, but the .class file also has to be within the
correct directory structure. If, as I suspect, Arrays2 is a class in the
com.bruceeckel.util package, then the class file must be at
.\com\bruceeckel\util\Arrays2.class relative to where you're trying to
compile. Since you apparently haven't compiled Arrays2 yet, it's looking in
that directory for the Arrays2.java file and not finding it.
PageV - 21 May 2004 04:47 GMT
> > I get
> > DoubleArr.java:11: cannot access Arrays2
[quoted text clipped - 40 lines]
> compile. Since you apparently haven't compiled Arrays2 yet, it's looking in
> that directory for the Arrays2.java file and not finding it.

Array2.class is in .\com\bruceeckel\util.  Array2.java is in  .\
I am wondering why the compiler looks at Array2.java at all.
Shouldn't it find Array2.class, which it does do if I rename or remove
Array2.java?
  I don't want to manually create folders for java files, -D D:\classes
creates the directories for the class files for me.  I was able to compile
files in the top directory.
Ralph
Bjorn Abelli - 21 May 2004 08:35 GMT
"PageV" wrote...

> Array2.class is in .\com\bruceeckel\util.  Array2.java is in  .\
> I am wondering why the compiler looks at Array2.java at all.

The compiler doesn't *know* that Array2 is supposed to be
com.bruceeckel.util.Array2. In your code it's only named as Array2, which
*could* mean that it is in the default package (.\) or in java.lang (which
is "imported by default").

> Shouldn't it find Array2.class, which it does do
> if I rename or remove Array2.java?

As it doesn't know if it is in the default package, java.lang or
com.bruceeckel.util, it looks for it in all three places.

As it finds Array2.java in .\ first, but without corresponding .class in the
same directory, it simply believes that it has to compile it.

Then it discovers that the current location of the .java file doesn't
correspond to what is said inside, that it belongs to package
com.bruceeckel.util, and hence an error occurs.

As it already found a possible .java-file, it doesn't look further to see if
there is an Array2.class or Array2.java in the other directories, but as you
noticed, if it *doesn't* find it in the "default package", it continues to
search, and finds the class-file in the correct directory.

Here is another explanation of the implications:
http://www.kevinboone.com/classpath.html

// Bjorn A
PageV - 22 May 2004 02:52 GMT
> "PageV" wrote...
> >
[quoted text clipped - 28 lines]
>
> // Bjorn A

Thanks

Ralph


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.