Forums Register Login

compilation error

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Try posting your code, and we'll have a look...
Geoffrey

------------------
Sun Certified Programmer for the Java 2 Platform
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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 (.).
+Pie Number of slices to send: Send
thanks,
for you comment that resolve my problem
+Pie Number of slices to send: Send
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,
+Pie Number of slices to send: Send
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,
+Pie Number of slices to send: Send
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


+Pie Number of slices to send: Send
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.)
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
Yeah, but is it art? What do you think tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1015 times.
Similar Threads
Pass by ref- pgm err
Static Doubly Linked Lists....
problem in migrating weblogic application to Jboss
Why I cannot extend a class from java.lang.Package
package javax.faces.component does not exist
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:33:35.