"AWT-EventQueue-0" java.lang.StackOverflowError

1k views Asked by At

I keep getting this errors and i don't know the cause, I'll mark the error with comments

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.awt.Win32GraphicsConfig.getBounds(Native Method)
at sun.awt.Win32GraphicsConfig.getBounds(Win32GraphicsConfig.java:222)
at java.awt.Window.init(Window.java:505)
at java.awt.Window.<init>(Window.java:537)
at java.awt.Frame.<init>(Frame.java:420)
at java.awt.Frame.<init>(Frame.java:385)
at javax.swing.JFrame.<init>(JFrame.java:189)
at ParqueoSQL.ParqueoAstor.<init>(ParqueoAstor.java:42)
at BaseSQL.Totales.<init>(Totales.java:20)
at ParqueoSQL.ParqueoAstor.<init>(ParqueoAstor.java:31)
at BaseSQL.Totales.<init>(Totales.java:20)

the file contents over 1700 code lines.
here's part where its shows the error

public class ParqueoAstor extends javax.swing.JFrame {

public static String sre="";
public static String srs="";
public static String pl="";



modelo m=new modelo();
Hora h=new Hora();
Fecha f=new Fecha();
Precios p=new Precios();
Totales t=new Totales();   //ParqueoSQL.ParqueoAstor.<init>(ParqueoAstor.java:31)
UsuarioSQL u=new UsuarioSQL();
DateFormat dateFormat = new SimpleDateFormat ("hh:mm:ss");
DecimalFormat df=new DecimalFormat("¢0.00");


String hoy=""+f.obtenerFechatabla();

String ubic="C:/Parqueo/export/Excel/"+hoy;
String direc="C:/Parqueo/export/Excel";

public ParqueoAstor() {  //ParqueoSQL.ParqueoAstor.<init>(ParqueoAstor.java:42)
    initComponents();
    bloquear();
    bloqueonivel();
    bloquearusu();
    bloquearPrecios();
    m.cargartablaclientes(jTable1,f.obtenerFecha());
    u.cargartablausuarios(jTable3);
    exportartabla();
    jLabel17.setText(u.pnombre);
    jLabel18.setText(u.pnivel);
    t.ultRegistroF();
    //t.ultRegistroMY();
    t.totHoy(jLabel46);
    t.totMes(jLabel48);
    //t.verificar(f.obtenerFecha(),f.fech());
}

and the other file

public class Totales {

Hora h=new Hora();
Fecha f=new Fecha();
modelo m=new modelo();
ConexionBD sql=new ConexionBD();
ParqueoAstor p=new ParqueoAstor();    //BaseSQL.Totales.<init>(Totales.java:20)
DecimalFormat totalf=new DecimalFormat("0.00");
//String tipo;

i've been working on this for hours and a I don't get it

1

There are 1 answers

0
VGR On

You can see what’s happening in the lines of the stack trace. Observe the repeated ParqueoAstor.<init> and Totales.<init> lines.

When an instance of the ParqueoAstor class is created, it creates a new Totales instance:

Totales t=new Totales();

When an instance of the Totales class is created, it creates a new ParqueoAstor instance:

ParqueoAstor p=new ParqueoAstor();

That creates another Totales instance, which creates another ParqueoAstor instance, which creates another Totales instance, which creates another ParqueoAstor instance, and so on… until the stack overflows from all the nested constructor calls.

You will need to change your design so the dependency flows in only one direction. One class can depend on another, but they must not have mutual dependencies on each other.