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
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...
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 (.).
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,
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
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.)
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.
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 by:autobot
Yeah, but is it art? What do you think tiny ad?
a bit of art, as a gift, that will fit in a stocking