• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol

 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a very basic problem, I think, I am crazy?

There are two files:

public class Z{}

public class Y extends Z {}

These two files are saved in the same folder. I can not compile the file called Y.java.

This is the message:

cannot find symbol
symbol class Z
public class Y extends Z {}

What is wrong?

Urs
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't given enough details.

Do the two files have package declarations? In which case you might only be able to compile them in the order Z--->Y. Try that.
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They do not have package declarations. It is very basic.

Z.java
Y.java

The source code is writen above. It is really a stupid problem, but I need to understand it.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are the files both named correctly? is your CLASSPATH set?
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
show us your actual code,
show us the actual error message,

use code tags!
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two files saved in the same folder:

Z.java:
public class Z{}

Y.java:
public class Y extends Z {}

That is all. I can compile the file Z.java. But I can not compile the file Y.java. I get the following message:

cannot find symbol
symbol class Z
public class Y extends Z {}
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the folder where Z.class is generated in the CLASSPATH? If you have
"." in the classpath, you should be able to compile from the folder where Z.class is present.
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have saved both files on the desktop. I added CLASSPATH in the environment variable.

C:\Dokumente und Einstellungen\Urs W�fler\Desktop

This is saved in CLASSPATH.

But it does not work. I do not properly understand CLASSPATH.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cd C:\Dokumente und Einstellungen\Urs W�fler\Desktop
javac -classpath . Y.java
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Do one thing, First after compiling z.java..search it class file where it got generated...compiler is not able to find out that file..!!
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked.

javac -classpath . Y.java

This was the solution. Thank you.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great!

You can get to know about these common problems here.

Also you can read this thread about How to set the classpath
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic