This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error: cannot resolve symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error: cannot resolve symbol" Watch "Error: cannot resolve symbol" New topic
Author

Error: cannot resolve symbol

Atreo De Maio
Greenhorn

Joined: Nov 28, 2005
Posts: 10
I have that error and I don't know what else I can try.
The situation is the following:

'PuntoI.java' is an interface.
'Punto.java' is a class.
'Punto2Di.java' pretends to be an implementation of 'PuntoI.java'

----jGRASP exec: javac -g D:\Universidad\2_Edi\2005-2006\PrJAVA\Punto2Di.java

Punto2Di.java:13: cannot resolve symbol
symbol : class PuntoI
location: class estructuras.Punto2Di
public class Punto2Di implements PuntoI
^
Punto2Di.java:22: cannot resolve symbol
symbol : class Punto
location: class estructuras.Punto2Di
public Punto construir(double X, double Y)


Any idea of the solution?

Thank you very very much for your attention and help.


Hey! Thanks a lot for your help.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Are the .class files in the same directory? What is your CLASSPATH?
Atreo De Maio
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Hi!

Thank you for answering

I don't know my CLASSPATH because jGrassp does everything for you.

And yes, the *.class files are there: 'Punto.class' and 'PuntoI.java'.


Any idea?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Is there a PuntoI.class file? Are the .java files in the same directory as the .class files?


Java API Documentation
The Java Tutorial
Atreo De Maio
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Hi Layne Lund, thanks a lot for your answer!

Maybe it's due to in 'Punto2Di' (the one than implements 'PuntoI') I've writen import Punto.

'Punto' (it's a class), 'PuntoI' (interface) 'Punto2Di' (implementation) have in the first line this sentence:

package structures;

In the folder I only have these files:
'Punto.java' (and 'Punto.class')
'PuntoI.java' (and 'Punto.class')
'Punto2Di.java'

Should I write: 'import structures.PuntoI' ?

Has my error anthing to do with that?


Thanks for your help
Atreo De Maio
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Hi again Keith and Layne!!

I think I've done some progress...

I've writen the class 'Punto' and the interface 'PuntoI' inside a file called 'estructuras.java'.
When I compile two files are generated: 'Punto.class' and 'PuntoI.class'.

But I'm still trying with my other friend 'Punto2Di.java'. It doesn't compile due to this:

Punto2Di.java:1: package estructuras does not exist
import estructuras.*;
^
Punto2Di.java:13: cannot access PuntoI
bad class file: .\PuntoI.class
class file contains wrong class: estructuras.PuntoI

I have another change to tell. Now the folder where these files are is called as the package 'estructuras'.

Maybe the error is because I have to include the package somewhere or I have to specify by the CLASSPATH or PATH variables.
I'm still very very new to these parameters and variables, but I'm trying...

Am I right?
Any suggestion?

Thank you very much for your help it's being great.
Atreo De Maio
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Sorry, I haven't written al the lines the compiler shows me about the error.
Here they are:

----jGRASP exec: javac -g D:\Universidad\2_Edi\2005-2006\estructuras\Punto2Di.java

Punto2Di.java:1: package estructuras does not exist
import estructuras.PuntoI;
^
Punto2Di.java:13: cannot access PuntoI
bad class file: .\PuntoI.class
class file contains wrong class: estructuras.PuntoI
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class Punto2Di implements PuntoI
^
2 errors


Help me please.
Thanks a lot
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It sounds like you need some help understanding how classes and packages should map to the file structure. First of all, if you have a public class in a file, then the file MUST have the same name as the class. For example, class Punto should be in a file named Punto.java. For now, I suggest that you create one file per class and make all your classes public. Now these files should go in a subdirectory that has the same name as the package that contains them.

So let's say you have a directory called c:\java where you store all your source code. For the package named estructuras you need to create a subdirectory with the same name (i.e. c:\java\estructuras). Then you put all of the .java files in this subdirectory. Remember that each file should only contain one class: the class that the file is named after.

Now when you compile it from the command line, you should change to the c:\java directory and type the following command:

This will compile the Punto class. You can do the same for each of your classes, although javac is smart enough to compile any that are needed for the current class if they haven't been compiled yet. For instance, the above will automatically compile PuntoI.java since it contains the interface that Punto2Di implements.

I hope this helps. If you still have problems, please come back and let us know what you have done so far. You should describe the file structure you created as well as the commands you used to compile and the error messages you get.

HTH

Layne
Atreo De Maio
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Hi!

Ok, let's go through it.
I've done changes following your suggestions.
I have a folder called 'estructuras' which has three files:
Punto.java
PuntoI.java (interface)
Punto2Di.java (implementation)

When I compile 'Punto2Di.java' outside 'estructuras' folder:

----jGRASP exec: javac -g D:\Universidad\2_Edi\2005-2006\Punto2Di.java

Punto2Di.java:13: cannot access estructuras.PuntoI
bad class file: .\estructuras\PuntoI.class
class file contains wrong class: PuntoI
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class Punto2Di implements PuntoI
^
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

And when I compile 'Punto2Di.java' inside 'estructuras' folder:

----jGRASP exec: javac -g D:\Universidad\2_Edi\2005-2006\estructuras\Punto2Di.java

Punto2Di.java:1: package estructuras does not exist
import estructuras.*;
^
Punto2Di.java:13: Punto2Di is not abstract and does not override abstract method Distancia(PuntoI) in PuntoI
public class Punto2Di implements PuntoI
^
Punto2Di.java:22: construir(double,double) in Punto2Di cannot implement construir(double,double) in PuntoI; attempting to use incompatible return type
found : Punto
required: void
public Punto construir(double X, double Y)
^
Punto2Di.java:24: cannot resolve symbol
symbol : method Punto (double,double)
location: class Punto2Di
Punto(X,Y);
^
Punto2Di.java:47: cannot resolve symbol
symbol : method Abcisa ()
location: class Punto
distancia = ( Math.pow((abcisa - puntoAux.Abcisa()),2)
^
Punto2Di.java:48: cannot resolve symbol
symbol : method Ordenada ()
location: class Punto
+ Math.pow((ordenada - puntoAux.Ordenada()),2) );
^
6 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.


Long ago I tried to set my PATH and CLASSPATH for compiling from the command line wherever in my hard disk. As I didn't achieve it I downloaded jGrasp because I can compile files in other folders than ...\bin

Thanks a lot.
I only can say thank you and try.
Thank you very much
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I have two suggestions to help you fix this:

1) Make sure you have "package estructuras;" at the top of the PuntoI.java file.
2) Delete all .class files before you compile again.

If you are interested in revisiting setting the PATH so you can compile from the command line, you should check out step 5 in the Java Installation Notes. I think this might be your best bet. Otherwise, you will have to figure out how to set the classpath under JGrasp. I'll be willing to help you either way, but I'm already familiar with the command-line. It will take more time to figure out how to do all this in JGrasp instead.

Also, are you placing the Punto2Di class in the estructuras package (i.e. does Punto2Di.java have "package estructuras;" at the top)? From the output in your most recent post, you obviously moved the file, but did you change the source code so that Java knows it's in a different package? Also, Note that you do not need to import classes that are in the same package. So when you try with Punto2Di in the estructuras package, you don't need the "import estructuras.*;" statement at all. Perhaps removing this line will fix the errors. At least it will give different errors for us to work with.

Well, let me know if any of these suggestions help you.

Regards,

Layne
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
p.s. If you choose to try to set the PATH variable, be sure to close any command-line windows that you have open and start a new session. The system variables don't take effect until you open a new command-line.

Layne
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Error: cannot resolve symbol
 
Similar Threads
SecureServer error
Servlet Login
error when testing...any help will be appreciated
Pass by ref- pgm err
compilation error