Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error

 
jose coria
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try posting your code, and we'll have a look...
Geoffrey

------------------
Sun Certified Programmer for the Java 2 Platform
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,
for you comment that resolve my problem
 
jose coria
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Daniel Moreno
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic