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();

}

[4198 byte] By [River_Platea] at [2007-11-27 10:00:24]
# 1
What is the exact error message?
cotton.ma at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 2
Cannot find symbol class PilaThe compiler says that this line: Pila p = new Pila();is causing the problem..
River_Platea at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 3
what constructor do you define?now what constructor do you call?
petes1234a at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 4
what do you mean?yes there is a constructor, but in this case i want to call those methods directly.
River_Platea at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 5
> 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!
cotton.ma at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 6

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.

petes1234a at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 7
It's the class, not the constructor, that it can't find.How are you compiling?
jverda at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 8
> sted no tiene un constructor sin par醡etros!yyyy, no debas darle la respuesta directamente!
petes1234a at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 9
> It's the class, not the constructor, that it can't> find. He is calling a non-existent constructor though....
cotton.ma at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 10
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 :-/
River_Platea at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 11
> > sted no tiene un constructor sin par醡etros!> > yyyy, no debas darle la respuesta directamente!Mi espa駉l ella no es buena.
cotton.ma at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 12
> There is a constructor, and it does have paramaters..> >Okay. Then calling like this...new Pila();is no good.
cotton.ma at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 13

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

jverda at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 14
> 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
petes1234a at 2007-7-13 0:31:43 > top of Java-index,Java Essentials,New To Java...
# 15
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 > top of Java-index,Java Essentials,New To Java...
# 16

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..

River_Platea at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 17

> 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

petes1234a at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 18
> You call a constructor with the> new keyword.Or super(...) or this(...)
jverda at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 19
> Or super(...) or this(...)Yep. Thanks for the correction.
petes1234a at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 20
> 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.... :(
petes1234a at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 21
i'm not mexican by the way :-/ if u want to learn spanish get a mexican girlfriend ;-) or colombian, or cuban ... whatever :-P lol.
River_Platea at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 22
> i'm not mexican by the way :-/ Brazilian no?
cotton.ma at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 23
> 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...
petes1234a at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 24
you can have a short affair... tell her its part of the learning process :-D
River_Platea at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 25
> Calling a class http://www.yellowpages.com/
Navy_Codera at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 26
>Brazilian no? this looks too fun to stay out of.. Brazilians speak Portuguese which is different from SpanishMessage was edited by: pberardi1
pberardi1a at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...
# 27

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);

vikasunjhaa at 2007-7-21 23:14:08 > top of Java-index,Java Essentials,New To Java...