1

So I'm making a payroll application and ran into a problem. Every time I go to run it, it comes up with a stackoverflow error. I can't seem to find out the error. I have been stuck on the problem for a while but any help would be much appreciated. I commented out the mainform variable on assign bonus and it seemed to work but i need that variable to get back to other forms.

Exception in thread "main" java.lang.StackOverflowError
    at sun.awt.CGraphicsConfig.nativeGetBounds(Native Method)
    at sun.awt.CGraphicsConfig.getBounds(CGraphicsConfig.java:56)
    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 oca.project.MainForm.<init>(MainForm.java:91)
    at oca.project.AssignBonusForm.<init>(AssignBonusForm.java:80)
    at oca.project.MainForm.<init>(MainForm.java:22)

main class

package oca.project;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class OCAProject {

 static ArrayList<Person> persons = new ArrayList<>();

    public static void main(String[] args) {

         CEO JamesMint = new CEO();
        //making objects 
 AdministrationManager BillJohns = new AdministrationManager(JamesMint);
FinancialAdministrator EricWhite = new FinancialAdministrator(JamesMint);
 persons.add(JamesMint);
 persons.add(BillJohns);
persons.add(EricWhite);

 //declaring form and passing arraylist as parameter
        MainForm frame = new MainForm(persons);
        frame.setVisible(true); 
    }
}

mainframe class

package oca.project;
import java.util.ArrayList;

public class MainForm extends javax.swing.JFrame {
  //array list to hold the report items
    private ArrayList<PayrollReportItem> payRolllist = new ArrayList<>();

  AssignBonusForm assignFrame = new AssignBonusForm(payRolllist);
void setList(ArrayList<Person> persons) {
//sets arraylist

      assignFrame.setPersons(persons);


   }
 public MainForm(ArrayList<Person> persons) {
           initComponents();
        setList(persons);
       }

 private void btnAssignBonusActionPerformed(java.awt.event.ActionEvent evt) {                                               

//to open assign bonus form
      assignFrame.setVisible(true);
        this.dispose();


    }   

assign bonus form

package oca.project;

import java.util.ArrayList;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;


/**
 *
 * Form that allows managers assign bonuses to their subordinates 
 */
public class AssignBonusForm extends javax.swing.JFrame  {

 static ArrayList<Person> persons = new ArrayList<>();

  /**
     * Creates new form AssignBonusForm
     * @param payRolllist
     */


    public AssignBonusForm(ArrayList<PayrollReportItem> payRolllist) {
        initComponents();


      System.out.println(persons);
    } 

    private AssignBonusForm() {


    }

    public void setPersons(ArrayList<Person> persons) {
    AssignBonusForm.persons = persons;
    }

    public ArrayList<Person> getPersons() {
        return persons;
    }

MainForm form = new MainForm(persons);

   private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {                                        

        form.setVisible(true);

        this.dispose();
    }                                       
2
  • Your post is missing the stacktrace of the error. Commented Dec 29, 2017 at 0:37
  • Posted the error. Commented Dec 29, 2017 at 0:41

1 Answer 1

4

It's hard to tell with the poor formatting, but, doesn't this seem a bit odd to you?

public class MainForm
    ...
    AssignBonusForm assignFrame = new AssignBonusForm(payRolllist);

public class AssignBonusForm
    ...
    MainForm form = new MainForm(persons);

What do you think will happen when you create a new MainForm which creates a new AssignBonusForm which creates a new MainForm which creates a new AssignBonusForm which creates a new MainForm which creates a new AssignBonusForm which creates a new MainForm which creates a new AssignBonusForm which creates a new MainForm which creates a new ...

You can see this right in your stacktrace:

...    
at oca.project.MainForm.<init>(MainForm.java:91)
at oca.project.AssignBonusForm.<init>(AssignBonusForm.java:80)
at oca.project.MainForm.<init>(MainForm.java:22)

Why is MainForm in there twice?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.