I'm very new to Java or any programming for that matter. So currently trying to teach myslef using a book called Java First Contact.
Have got to the chapter3 exercises. Tryin to build a program that uses a class file that came on a disk with the book. I've loaded the files on the disk into the directory of the file I'm building. Following the books instructions I've written this staement at the top of my file:
Which I believe tells the compiler to look in a subdirectory called classes then one called bytecodes. In the bytecodes directory is the class file i want to use.
I've also set the classpath to look in this directory by writting
C:\ set classpath=JavaFC;classes;bytecode
However when trying to compile my file I get the message
Is your error during compilation or execution? It appears to be execution. You compile witht the javac.exe command. You execute with the java.exe commmand. Please copy the full text of the console when the error occurs showing what you typed in and what happened.
The import statement is a dotted path that the compiler uses to extend the classpath to find class definitions. It concatenates that path to the classpath to find the class.
>import classes.bytecode.*; This says to look in the folder: classes\bytecode\ for class definitions.
Joined: Sep 27, 2005
When you say it looks for class definitions you mean the filename.class files right?
The error occurs when compiling.
I have been fiddling a bit and now get this error (here is a copy of the dos screen)
Microsoft Windows 2000 [Version 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp.
C:\Documents and Settings\G-Force>cd c:\
C:\Java\JavaFC>javac FirstExercise.java FirstExercise.java:6: cannot access classes.bytecode.Person bad class file: .\classes\bytecode\Person.class class file contains wrong class: java.lancs.Person Please remove or make sure it appears in the correct subdirectory of the classpa th. import classes.bytecode.Person; // Locate required files ^ 1 error
It looks like the Person class thinks it's in a different package than the one you specified. I'd try moving the Person.class to a .\java\lancs directory and then changing the import statement in your code to "import java.lancs.*;" and see how that works.