Stack overflows are often due to recursion gone wild, so I looked for anything that referes to itself. We usually see a method call itself, but you found an interesting way to do it with object references. Look at your member variable definition:
PilaEnlazada n=new PilaEnlazada();
When your main() method creates a new instance of PilaEnlazada, this variable is initialized, and it creates another instance. And that new one creates another instance. As my wife always says about children's dirty laundry, it just never ends.
Describe your objective to us a bit in plain language (not code) and see if a better way to do it in code comes to mind.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Problems found: The class variable 'n' and it's initialization
From the main when PilaEnlazada nuevo=new PilaEnlazada(); is executed a recursion is started.
Below I will put the path of the recursion...
step 1. When new PilaEnlazada() is executed the class PilaEnzalada is loaded to memmory. If already loadecd ignore this step. Step 2. JVM allots memory for all class variables. Step 3. All class variables including 'n' will be initialized before executing the statements in constructor. Step 4. As part of intializing n, the statement new PilaEnlazada() will be executed Step 5. As part of step 4 above Steps 1 to 5 will be executed again.
Solution to the program: (solution to the program is different from solution to the problem, I will explain the problem later)Remove recursion caused by class variable 'n'. Remove class variable 'n' and all it's references. The 'current' PilaEnlazada can be refrenced by 'this'. On the left hand side of statements, 'this' is implicit even if you don't specify them. ex:
On the right hand side of statements, 'this' is explicitly needed.
Solution to the problem: Solution is specific to the goal. Goal identification: What the programmer trying to accomplish here is either to establish a linked list of 'PilaEnlazada's or a collection of 'PilaEnlazada's. Since PilaEnlazada itself have a behaviour called push it is assumed that the programmer is trying to impliment a 'stack kind of collection' for 'PilaEnlazada's. If the goal is different from assumed please let me know.
Solution: Needs atleast two types need to be defined. One type is PilaEnlazada. Another type is a 'stack kind of collection' which holds PilaEnlazada. The code for PilaEnlazada may look like.
The code for PilaEnlazadaStack may look like follows
PilaEnlazadaHolder can be made as an inner class to PilaEnlazadaStack