0

Hm i get a strange problem. when i creating new instance of class i get StackOverflowExcepion :)

Here is code:

public partial class PlayerChooser : Window
{
public PlayerChooser()
    {
        InitializeComponent();
        textBoxPlayer1Name.Visibility = Visibility.Hidden;
        textBoxPlayer2Name.Visibility = Visibility.Hidden;
        textBoxPlayer3Name.Visibility = Visibility.Hidden;
        textBoxPlayer4Name.Visibility = Visibility.Hidden;

    }

    public static String player1Name;
    public static String player2Name;
    public static String player3Name;
    public static String player4Name;
    ...

    PlayerChooser.player1Name = textBoxPlayer1Name.Text;
    PlayerChooser.player2Name = textBoxPlayer2Name.Text;
    TwoPlayers501_new twoPlayers501_new = new TwoPlayers501_new();
    twoPlayers501_new.Show();
    ...
}

and class and constructor where exception occurs

public partial class TwoPlayers501_new : Window
{
    public TwoPlayers501_new()
    {
        InitializeComponent();

        textBlockPlayer1Name.Text = PlayerChooser.player1Name;
        textBlockPlayer2Name.Text = PlayerChooser.player2Name;
    }
    ...
}

thanx in advance, it is probably some kind of triviality...

1
  • 3
    What does your stack trace look like when the exception occurs? Commented Nov 30, 2010 at 16:23

3 Answers 3

5

Do you have an event handler somewhere performing an action that changes one of those properties based on the property having been changed?

Short version: There isn't enough information here to debug your problem.

Suggestion: Debug your program and when you get the stackoverflowexception, check out the callstack. I suspect that there's a method or series of methods that cycle infinitely in your stack.

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

3 Comments

no those values are entered once, and only used afterwards, never changed. i tried to put textblocks under comments, like this public TwoPlayers501_new() { InitializeComponent(); //textBlockPlayer1Name.Text = PlayerChooser.player1Name; //textBlockPlayer2Name.Text = PlayerChooser.player2Name; } and same thing occurs.
What's your stacktrace look like on the stackoverflow exception?
[External Code] PikadoRacunaljka.exe!Pikado_Racunaljka.TwoPlayers501_new.TwoPlayers501_new() Line 32 C# and this repeat until stack is overflown. Line 32 is textBlockPlayer1Name.Text = PlayerChooser.player1Name;
0

You are recursing on yourself:

PlayerChooser.player1Name = textBoxPlayer1Name.Text;
PlayerChooser.player2Name = textBoxPlayer2Name.Text;

textBlockPlayer1Name.Text = PlayerChooser.player1Name;
textBlockPlayer2Name.Text = PlayerChooser.player2Name;

2 Comments

no i am not, there is textBoxPlayer1Name.Text and textBlockPlayer1Name.Text TextBox, and TextBlock
How is this recursion? int a = b; b = a; doesn't recurse.
0

Ok, I find out what the hell is wrong with my program. Something went wrong with C# compiler I guess. Because when i removed underscore from class name (now is TwoPlayers504New) everything started working properly.

Thanks a lot Microsoft.

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.