GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes compilation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation error" Watch "compilation error" New topic
Author

compilation error

jose coria
Greenhorn

Joined: Sep 22, 2001
Posts: 6
hi
im a beginner java programmer, and i have the next message
Circulo.java:2: cannot resolve symbol
symbol : class Figura
location: class paquete1.Circulo
public class Circulo extends Figura{
im trying to package the classes, but i have this error, when i
delete the package paquete1; line in the class, its ok.
could you help resolve this?
thank a lot
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
Try posting your code, and we'll have a look...
Geoffrey

------------------
Sun Certified Programmer for the Java 2 Platform


Sun Certified Programmer for the Java 2 Platform
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I'd suggest that if you're a beginner in Java, it would really make more sense to post in the "Java in General (Beginner)" forum. I'm moving this there now...

"I'm not back." - Bill Harding, Twister
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
When you want to make a class a part of a package, you should create a directory with that package name ("paquete1"), and put the class in that package. But don't try to compile from that directory - compile from the directory above, using someting like
javac paquete1/Circulo.java
Also make sure your classpath includes the current directory (.).
jose coria
Greenhorn

Joined: Sep 22, 2001
Posts: 6
thanks,
for you comment that resolve my problem
jose coria
Greenhorn

Joined: Sep 22, 2001
Posts: 6
well, i did that jim advise me, and resolve the error
but when i add a class inheritance, esfera ocurre other error
this is the code im using:
package paquete;
public abstract class Figura{
int x,y;
public Figura(int x, int y){
this.x=x;
this.y=y;
}
public abstract double area();
}
package paquete;
public class Circulo extends Figura{
double radio;
public Circulo(int x, int y, double radio){
super(x,y);
this.radio=radio;
}
public double area(){
return(Math.PI*(radio*radio));
}
}
// until up theres not problem
package paquete1;
class Esfera extends Circulo{
public Esfera(int x, int y, double radio){
super(x,y,radio);
}
public double area(){
return(4*(Math.PI*(radio*radio)));
}
}
here is the other error:
paquete\Esfera.java:2: cannot resolve symbol
symbol : class Circulo
location: class paquete1.Esfera
class Esfera extends Circulo{
^
paquete\Esfera.java:7: cannot resolve symbol
symbol : variable radio
location: class paquete1.Esfera
return(4*(Math.PI*(radio*radio)));
^
paquete\Esfera.java:7: cannot resolve symbol
symbol : variable radio
location: class paquete1.Esfera
return(4*(Math.PI*(radio*radio)));
^
3 errors
-----------------------------------------------------------
thank again,
jose coria
Greenhorn

Joined: Sep 22, 2001
Posts: 6
sorry,
i saw my error, i add a number 1, in the package name in esfera class. i erase it, and all is ok.
thanks,
parul patidar
Ranch Hand

Joined: Sep 07, 2001
Posts: 53
use
import paquete.*;
after package statement in third class
parul patidar
Originally posted by jose coria:
well, i did that jim advise me, and resolve the error
but when i add a class inheritance, esfera ocurre other error
this is the code im using:
package paquete;
public abstract class Figura{
int x,y;
public Figura(int x, int y){
this.x=x;
this.y=y;
}
public abstract double area();
}
package paquete;
public class Circulo extends Figura{
double radio;
public Circulo(int x, int y, double radio){
super(x,y);
this.radio=radio;
}
public double area(){
return(Math.PI*(radio*radio));
}
}
// until up theres not problem
package paquete1;
class Esfera extends Circulo{
public Esfera(int x, int y, double radio){
super(x,y,radio);
}
public double area(){
return(4*(Math.PI*(radio*radio)));
}
}
here is the other error:
paquete\Esfera.java:2: cannot resolve symbol
symbol : class Circulo
location: class paquete1.Esfera
class Esfera extends Circulo{
^
paquete\Esfera.java:7: cannot resolve symbol
symbol : variable radio
location: class paquete1.Esfera
return(4*(Math.PI*(radio*radio)));
^
paquete\Esfera.java:7: cannot resolve symbol
symbol : variable radio
location: class paquete1.Esfera
return(4*(Math.PI*(radio*radio)));
^
3 errors

Gary Labowitz
Greenhorn

Joined: Aug 18, 2001
Posts: 5
In your compile of Esfera you have a package statement for pacquete1. The compiler tries to find the reference to Circulo by adding the package name to it (pacquete1.Circulo) and does not find it since Circulo is in pacquete.
You tell the compiler to try adding pacquete to the name of any class in your code by using an import statement:
import pacquete.*;
This will allow the compiler to find Circulo in the pacquete directory. (It will be looking for the class named pacquete.Circulo, which is the actual class name.)
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
Unless I'm very much mistaken this problem come down to access modifiers.
because you havn't specified an access modifier for your classes the default (package) modifer is assumed. So because you had a class in a different package it couldn't be seen by those outside of that package, that is why putting it in the same package made it work.


Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
Daniel Moreno
Greenhorn

Joined: Aug 10, 2001
Posts: 2
Hello
Just one thing, instead of creating directories for each package you declare, you should use the '-d' option of javac, that way the compiler will create the directories.
"javac -d . *.java" will create the directory structuture below the actual directory.
Daniel
 
GeeCON Prague 2014
 
subject: compilation error