• Post Reply Bookmark Topic Watch Topic
  • New Topic

New error, what does it mean?  RSS feed

 
Giles Buist
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Julien Grenier
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe you forgot to import your class Person into
the other class.

also maybe posting some parts of the code would help

Julien
 
Giles Buist
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
SenthilKumar Ganesan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the person class is in different package use import statement.
Also check whether you compiled the file "Person.java
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Giles Buist
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Giles Buist
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok now it's saying this:

javac not found!!!

Have I deleted Java???

AARRRGGHHH!!!
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Giles Buist
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Giles Buist
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!