Calling a class
Hello ppl!
i'm trying to compile this 2 classes... One is supposed to call the other..
but the one that makes the call wont compile.. Here's the code.
Can anyone help? :-/
package Segundo_Parcial;
import java.util.*;
publicclass Pila{
int tope=-1;
int vec[];
Pila(int max){
vec=newint [max];
}
publicboolean llena(){/// Esta llena?
if (tope==vec.length-1)
returntrue;
else
returnfalse;
}
publicboolean vacia(){/// Es Vacia ?
if (tope==-1)
returntrue;
else
returnfalse;
}
publicvoid push(int dato){/// PUSH METHOD
if (llena()==true)
System.out.println("Overflow");
else
if (tope==-1)
{
tope=0;
vec[tope]=dato;
}
else
{
tope++;
vec[tope]=dato;
}
}
publicint pop(){/// POP METHOD
int aux;
if (vacia()==true)
{
System.out.println("La pila esta vacia");
return -1;
}
else
{
aux=vec[tope];
tope--;
}
return aux;
}
publicvoid Imprime_Datos(){
if(vacia()==true)
{
System.out.println("La pila esta vacia, ingrese datos primero:");
}
else
for(int Contador=0;Contador<vec.length;Contador++)
System.out.println("Los valores de la pila son:"+vec[Contador]);
}
}
-->Class that calls <--
[code]
package Segundo_Parcial;
public class TestPila {
public static void main(String args[]){
Pila p = new Pila();
p.Imprime_Datos();
p.push();
p.llena();
p.pop();
}
What is the exact error message?
Cannot find symbol class PilaThe compiler says that this line: Pila p = new Pila();is causing the problem..
what constructor do you define?now what constructor do you call?
what do you mean?yes there is a constructor, but in this case i want to call those methods directly.
> what do you mean?> > yes there is a constructor, but in this case i want> to call those methods directly.sted no tiene un constructor sin par醡etros!
what I mean is, the best way to fix your problem is to answer these two questions above. In fact, show me if you can
1) the signature of your constructor (for example: public Fubar(int myInteger)), and
2) exactly how you call it (for example: Fubar myFubar = new Fubar(5);)
Once you do this, you will see your error.
It's the class, not the constructor, that it can't find.How are you compiling?
> sted no tiene un constructor sin par醡etros!yyyy, no debas darle la respuesta directamente!
> It's the class, not the constructor, that it can't> find. He is calling a non-existent constructor though....
There is a constructor, and it does have paramaters.. I'm compiling with Jcreator..i even used the console.. it gives the same problem.. :-/ i'm getting more and more confused :-/
> > sted no tiene un constructor sin par醡etros!> > yyyy, no debas darle la respuesta directamente!Mi espa駉l ella no es buena.
> There is a constructor, and it does have paramaters..> >Okay. Then calling like this...new Pila();is no good.
I didn't look at the code, just "Cannot find symbol class Pila".
Of course, it's possible he typed in pieces of the error message rather than pasting in the complete, exact error message, e.g.,
cannot find symbol
symbol : constructor Pila()
location: class whatever.Pila
> There is a constructor, and it does have paramaters..縫ero, llamas el constructor con los par醡etros?do you call the constructor with the parameters?(actually it would be an argument, I think).Message was edited by: petes1234
If it's really saying it can't find the class, then either it's a classpath issue, or the class it's trying to find (Pila, I guess) had errors and did not compile.
jverda at 2007-7-21 23:14:07 >

Guys.. forget spanish :-/
ok so i'm calling a non existing constructor.. but how? cuz this is my constructor.
Pila(int max){
vec=new int [max];
}
Am i calling the class or the constructor there? Pila(); is a stack so if i delete that constructor i have no stack..
> Guys.. forget spanish :-/
>
> ok so i'm calling a non existing constructor.. but
> how? cuz this is my constructor.
>
> > Pila(int max){
>vec=new int [max];
>
>
>
> Am i calling the class or the constructor there?
> Pila(); is a stack so if i delete that constructor i
> have no stack..
You are doing neither. You are defining a constructor there. You call a constructor with the new keyword.
If you want to be able to call your class's constructor with and without arguments, then define two constructors: one with parameters, the other without.
Your options:
a) define two constructors (or as many as needed), with and without parameters. Then you can initialize your objects (call constructors) with or without arguments.
b) define constructor with parameter only. Then you MUST initialize your objects with a parameter.
If your program logic doesn't hold up in this situation, then something has to change. You may have to always initialize your object with a parameter.
Message was edited by:
petes1234
> You call a constructor with the> new keyword.Or super(...) or this(...)
jverda at 2007-7-21 23:14:08 >

> Or super(...) or this(...)Yep. Thanks for the correction.
> Guys.. forget spanish :-/ But I can't. I am going to Mexico City in 2 weeks, and my spanish scks big time. I'm trying to review it, but it just won't stick.... :(
i'm not mexican by the way :-/ if u want to learn spanish get a mexican girlfriend ;-) or colombian, or cuban ... whatever :-P lol.
> i'm not mexican by the way :-/ Brazilian no?
> i'm not mexican by the way :-/ > > if u want to learn spanish get a mexican girlfriend> ;-) or colombian, or cuban ... whatever :-P lol.Let me discuss this with my wife, and I'll get back to you...
you can have a short affair... tell her its part of the learning process :-D
> Calling a class http://www.yellowpages.com/
>Brazilian no? this looks too fun to stay out of.. Brazilians speak Portuguese which is different from SpanishMessage was edited by: pberardi1
u got error because u define a constructor with parameter and u call default constructor .
In constructor ,if u can't define constructor than programme will take default constructor ,but if u declare any constructor than u have to call that constructor and that time default constructor will destroy..
so create oblect like this ...
Pila p = new Pila(intValue);