Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:15:43+00:00 2026-06-13T07:15:43+00:00

I keep getting a stack overflow error when I run this short program I

  • 0

I keep getting a stack overflow error when I run this short program I made! please help! Right now all it’s supposed to do is take the users input and print their position (in X and Y coordinates). I’m not sure what Stack overflow error is or how to fix it.

import java.awt.*;
import javax.swing.*;

public class ExplorerPanel extends JFrame {

    ExplorerEvent prog = new ExplorerEvent(this);

    JTextArea dataa = new JTextArea(15, 20);
    JTextField datain = new JTextField(20);
    JButton submit = new JButton("Submit");
    JTextField errors = new JTextField(30);

    public ExplorerPanel() {
        super("Explorer RPG");
        setLookAndFeel();
        setSize(400, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_…
        BorderLayout bord = new BorderLayout();
        setLayout(bord);

        JPanel toppanel = new JPanel();
        toppanel.add(dataa);
        add(toppanel, BorderLayout.NORTH);

        JPanel middlepanel = new JPanel();
        middlepanel.add(datain);
        middlepanel.add(submit);
        add(middlepanel, BorderLayout.CENTER);

        JPanel bottompanel = new JPanel(); 
        bottompanel.add(errors);
        add(bottompanel, BorderLayout.SOUTH);

        dataa.setEditable(false);
        errors.setEditable(false);

        submit.addActionListener(prog);

        setVisible(true);
    }

    private void setLookAndFeel() {
        try {
            UIManager.setLookAndFeel(
                                   "com.sun.java.swing.plaf.nimbus.NimbusLo…
            );
        } catch (Exception exc) {
            // ignore error
        }
    }

    public static void main(String[] args) {
        ExplorerPanel frame = new ExplorerPanel();
    }

}

public class ExplorerEvent implements ActionListener, Runnable {

    ExplorerPanel gui;
    Thread playing;
    String command;
    String gamedata;
    ExplorerGame game = new ExplorerGame();

    public ExplorerEvent(ExplorerPanel in) {
        gui = in;
    }

    public void actionPerformed(ActionEvent event) {
        String command = event.getActionCommand();
        if (command.equals("Submit")) {
            startPlaying();
        }
    }

    void startPlaying() {
        playing = new Thread(this);
        playing.start();
    } 

    void stopPlaying() {
        playing = (null);
    }

    void clearAllFields() {
        gui.dataa.setText("");
    }

    public void run() {
        Thread thisThread = Thread.currentThread();
        while (playing == thisThread) {

            // Game code
            game.Game();

        }
    }

}

public class ExplorerGame {

    ExplorerPanel gui = new ExplorerPanel();
    String command;
    int x = 1;
    int y = 1;

    public void Game() {
        command = gui.submit.getText().toLowerCase();

        if (command.equals("east")) {x--;}
        else if (command.equals("south")) {y--;}
        else if (command.equals("west")) {x++;}
        else if (command.equals("north")) {y++;}
        System.out.println(x + y);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:15:43+00:00Added an answer on June 13, 2026 at 7:15 am

    In ExplorerGame, you have declared: –

    ExplorerPanel gui = new ExplorerPanel();
    

    then, in ExplorerPanel: –

    ExplorerEvent prog = new ExplorerEvent(this);
    

    and then again, in ExplorerEvent: –

    ExplorerGame game = new ExplorerGame();
    

    This will fill the Stack with recursive creation of objects.

    ExplorerGame -> ExplorerPanel -> ExplorerEvent --+
        ^                                            |
        |____________________________________________|
    

    You want to solve the Issue?
    I’ll Suggest you: –

    • Throw away the code, and re-design your application. Having a cyclic dependency in your application is a big loop hole, showing a very poor design.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error and have no idea why. I googled and scanned
I keep getting this error on emulator: I copied this from a tutorial and
I keep getting this error Error in readPNG(destfile) : libpng error: PLTE: CRC error
I keep getting this error with my Play 2.0 application: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError:
I keep getting this stored procedure error (wrong number or types of the arguments)
Following the RailsTutorial, I keep getting this error message (one of four actually) when
Following the RailsTutorial, I keep getting this error message (one of four actually) when
Some help would be appreciated - keep getting Forbidden 403 error. Nginx configuration: listen
I keep getting thrown an error: This widget's parent does not implement HasWidgets. Of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.