Forums Register Login

New error, what does it mean?

+Pie Number of slices to send: Send
Hi all,

Just starting Java, having problems with some exercises fom a book.

I've built a file that uses a class (called Person) found in another file, but get this message when trying to compile:

c:\Java\JavaFC\javac FirstExercise.java
FirstExercise.java:23: cannot resolve symbol
symbol : constructor Person ()
location : class Person
Person person1 = new Person();
^
1 error

c:\Java\JavaFC

I don't entirely understand what the problem is?
+Pie Number of slices to send: Send
maybe you forgot to import your class Person into
the other class.

also maybe posting some parts of the code would help

Julien
+Pie Number of slices to send: Send
Ok, all i'm trying to do at the moment is create an instance of the class Person, called person1.

/** Author: Giles Buist

* Title: FirstExercise

* Date: 27/09/05

*/



import classes.bytecode.*;// Locate required files



public class FirstExercise// Declare the class name

{

public static void main(String[] args)

{

Person person1 = new Person();

}

}


The Person class file was one that I downloaded from the website that supports the book i'm working from
+Pie Number of slices to send: Send
If the person class is in different package use import statement.
Also check whether you compiled the file "Person.java
+Pie Number of slices to send: Send
 

Originally posted by SenthilKumar Ganesan:
Also check whether you compiled the file "Person.java"



Actually, you shouldn't need to do this. If the javac compiler has identified a dependency on a class that isn't compiled but whose .java file it can find, it will go ahead and compile the .java automatically. That's one of the reasons the .java files have to be in the correct package structure and be named as their class is named.

Back to the original poster's question:

Where is your Person class located? I note that you are importing classes.bytecode.* Is the first line of your Person class:

Probably not -- that would be confusing. The import statement imports files relative to the CLASSPATH, not the current path location.
+Pie Number of slices to send: Send
The Person class is definietly compiled, I have a Person.class file.

The Person.class file is in the subdirectory classes, then bytecode. The classes subdirectory is in the same directory as the file I'm now trying to compile FirstExercise.

The Person.java file that was compiled to Person.class has the following line at the top:

package classes.bytecode ;

The import statement imports files relative to the CLASSPATH, not the current path location.



I don't entirely understand what you mean by this. I tried using the following command

C:\ classpath=.java:javafc:classes:bytecode

it didn't work.

I appreciate everyone's help on this, keep it coming. Getting very frustrated as I feel I've followed the books instructions to the letter and it's still not working, can't really continue untill i get this sorted.
+Pie Number of slices to send: Send
Ok now it's saying this:

javac not found!!!

Have I deleted Java???

AARRRGGHHH!!!
+Pie Number of slices to send: Send
Don't worry you haven't deleted java.

You might try looking at the tutorial "first cup of java" or something like that on the Sun website.

edit: here's the link

Your First Cup of Java
[ September 28, 2005: Message edited by: Hentay Duke ]
+Pie Number of slices to send: Send
Ok I've cooled off a bit now so having another go.

Cheers for the Javac info, I had already done the tutorial you linked to but hadn't remebered the bit about setting environment variables, all sorted now.

So back to my main problem. The following is a printout of my DOS screen

C:\Java\JavaFC>dir
Volume in drive C is LOCAL DISK
Volume Serial Number is FCEB-A5BE

Directory of C:\Java\JavaFC

27/09/2005 12:06 <DIR> .
27/09/2005 12:06 <DIR> ..
27/09/2005 18:54 294 FirstExercise.java
27/09/2005 12:16 <DIR> classes
07/10/1997 12:08 3,304 Person.class
21/09/2005 16:24 7,793 Person.java
27/09/2005 12:36 440 FirstExercise.class
4 File(s) 11,831 bytes
3 Dir(s) 2,252,111,872 bytes free

C:\Java\JavaFC>javac FirstExercise.java
FirstExercise.java:23: cannot access Person
bad class file: .\Person.java
file does not contain class Person
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
Person person1 = new Person();
^
1 error

C:\Java\JavaFC>


It seems to be saying that the Person.class file doesn't exist, when you can clearly see using the dir command, that it does!!

Please help, I'm getting desperate.
+Pie Number of slices to send: Send
Eureka!!!

I've done it, it seems that I had copies of Person.class lying all over the place and somehow that was mucking things up.

Cheers to all who helped
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 947 times.
Similar Threads
create report with java
error when testing...any help will be appreciated
Unable to compile these java files
Create a user class help
Unable to find class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:59:41.