2016-04-10 17 views
0

プログラムを実行すると、ウィンドウがJavaプログラムから表示され、スタックオーバーフローエラーが発生する問題があります。私のコードで間違っていたところ、私が思っていたウィンドウが表示されないJavaおよびスタックオーバーフローエラー

public Ballot() { 
    bp.addBallot(); 
    frame.setTitle("Ballot"); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setSize(430,350); 
    frame.setLocation(300,100); 
    frame.setResizable(false); 
    Container cont = frame.getContentPane(); 
    cont.setLayout(null); 
    cont.setBackground(Color.GRAY); 
    ButtonGroup bg = new ButtonGroup(); 
    JRadioButton[] buttons = new JRadioButton[numButtons]; 
    for (int i = 0; i < buttons.length; i++) { 
     bg.add(buttons[i]); 
    } 
    JLabel label = new JLabel("Make your choice"); 
    label.setForeground(Color.BLUE); 
    label.setFont(new Font("Arial", Font.BOLD, 11)); 
    next = new JButton("Next"); 
    next.setForeground(Color.GREEN); 
    next.addActionListener(this); 
    panel = new JPanel(); 
    for (int i = 0; i < buttons.length; i++) { 
     panel.add(buttons[i]); 
    } 
    panel.add(next); 
    cont.add(panel); 
    setVisible(true); 
} 

:ここ

は、私は問題を抱えているコードのサンプルです。

助けるかもしれない追加のコード:

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.event.*; 
import java.util.*; 
import java.io.*; 

public class Ballot extends JPanel implements ActionListener { 
    JPanel panel; 
    JFrame frame = new JFrame(); 
    int numButtons; 
    JRadioButton[] buttons; 
    JButton next = new JButton(); 
    int votedOrNot; 
    BallotProgram bp = new BallotProgram(); 

    public Ballot() { 
    bp.addBallot(); 
    frame.setTitle("Ballot"); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setSize(430,350); 
    frame.setLocation(300,100); 
    frame.setResizable(false); 
    frame.pack(); 
    frame.setVisible(true); 
    Container cont = frame.getContentPane(); 
    cont.setLayout(null); 
    cont.setBackground(Color.GRAY); 
    ButtonGroup bg = new ButtonGroup(); 
    JRadioButton[] buttons = new JRadioButton[numButtons]; 
    for (int i = 0; i < buttons.length; i++) { 
     bg.add(buttons[i]); 
    } 
    JLabel label = new JLabel("Make your choice"); 
    label.setForeground(Color.BLUE); 
    label.setFont(new Font("Arial", Font.BOLD, 11)); 
    next = new JButton("Next"); 
    next.setForeground(Color.GREEN); 
    next.addActionListener(this); 
    panel = new JPanel(); 
    for (int i = 0; i < buttons.length; i++) { 
     panel.add(buttons[i]); 
    } 
    panel.add(next); 
    cont.add(panel); 
    setVisible(true); 
} 

public void actionPerformed(ActionEvent a) { 
    if (next.getText().equals("Cast Vote")) { 
     if (votedOrNot == 0) { 
      votedOrNot++; 
     } 
     else { 
     } 
    } 
    else if (next.getText().equals("Login to Vote")) { 
    } 
    } 

} 

そして、他のクラス:

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.event.*; 
import java.util.*; 
import java.io.*; 

public class BallotProgram { 

String[] choices; 
int numOfChoices; 

public ArrayList<Ballot> addBallot() { 
    File file = new File("ballots.txt"); 
    boolean exists = file.exists(); 
    ArrayList<Ballot> ballot = new ArrayList<Ballot>(); 
    Ballot b = new Ballot(); 
    try { 
     Scanner s = new Scanner(file); 
     while (s.hasNextLine()) { 
      int ballotID = s.nextInt(); 
      s.nextLine(); 
      String ballotTitle = s.nextLine(); 
      choices = new String[numOfChoices]; 
      b.buttons = new JRadioButton[b.numButtons]; 
      for (int i = 0; i < b.numButtons; i++) { 
       choices[i] = s.nextLine(); 
       b.buttons[i] = new JRadioButton(choices[i]); 
      } 
      Ballot bt = new Ballot(); 
      ballot.add(bt); 
     } 
     s.close(); 
    } catch (IOException f) { 
     System.out.println("can't find the file"); 
    } 
    return ballot; 
} 

そして、何私の端末は言う:

Exception in thread "main" Exception in thread "main" java.lang.StackOverflowError 
at sun.awt.X11GraphicsConfig.pGetBounds(Native Method) 
at sun.awt.X11GraphicsConfig.getBounds(X11GraphicsConfig.java:314) 
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 Ballot.<init>(Ballot.java:10) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 

おかげ

+0

'setVisible()'の前に 'pack()'を実行してみてください。 – Zulfe

+0

また、 'bp.addBallot()'の結果として実行しているものがstackOverflowExceptionを引き起こしていないことを確認してください。スタックトレースを提供した場合、何が間違っているかを簡単に伝えることができます。 – Zulfe

+0

が編集を行いました。なぜウィンドウが開かないのか+スタックオーバーフローエラーか分かりません。 – ABY

答えて

0

StackOverflowErrorのhAPP私たちの最高にうまくいく。地獄、そのウェブサイトはそれにちなんで命名されます。それはプログラマーが遭遇するすべての夢のようなものです。ほとんどの場合(新しいプログラマの場合)、あるメソッドがそれを呼び出すメソッドを呼び出すと、StackOverflowErrorが発生します。基本的に、メソッド呼び出しの無限ループが作成されます。あなたのスタックトレースからの情報に続いて

...

at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 
at BallotProgram.addBallot(BallotProgram.java:17) 
at Ballot.<init>(Ballot.java:18) 

私たちはあなたのプログラムの2点間の明確なループがあることがわかります。私たちはこれらの点を調査...

public ArrayList<Ballot> addBallot() { 
    ... 
    Ballot b = new Ballot(); 
    ... 
} 

public Ballot() { 
    bp.addBallot(); 
    ... 
} 

我々は無限ループがここで作成されていることがわかります。新しいBallotオブジェクトを作成すると、そのコンストラクタはbp.addBallot()を呼び出し、これが次にBallot b = new Ballot()という行にヒットし、コンストラクタに戻ります。新しいBallotオブジェクトを作成するプロセスでは、StackOverflowErrorがスローされるまで、新しいBallotオブジェクトが繰り返し作成されます。

+0

この問題を解決するにはどうすればよいですか?私は投票を初期化して開きたいと思っています – ABY

+0

私はあなたの 'Ballot'クラスのコンストラクタから' bp.addBallot() 'を削除するのが最善の方法だと思います。あなたがまだ完全にインスタンス化していないオブジェクトを追加する理由はわかりません。 – Zulfe

関連する問題