Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Please help me solve this problem, this is really urgent!

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help me solve this problem, this is really urgent!

    Hey, can you please help me out, every time i try to run this code I get an error:
    "Exception in thread "Thread-5" java.lang.StackOverflowError
    at players.K4LV1N.myMove(K4LV1N.java:115)
    at players.K4LV1N.move(K4LV1N.java:86)"

    Basically the move() method is called once every match by the SLArena and I am trying to store the moves in an array using the myMove() method.

    The code is:
    /**
    * Returns the next move in the sequence to SLArena.
    */
    public int move() {
    myMove ();
    if (++nextMove == LENGTH) {
    nextMove = 0;
    }
    if (moves[nextMove] == ROCK) {
    moves[nextMove] = PAPER;
    return PAPER;
    }
    if (moves[nextMove] == PAPER) {
    moves[nextMove] = SCISSORS;
    return SCISSORS;
    }
    if (moves[nextMove] == SCISSORS) {
    moves[nextMove + 1] = SPOCK;
    return SPOCK;
    }
    if (moves[nextMove] == SPOCK) {
    moves[nextMove] = LIZARD;
    return LIZARD;
    }
    moves[nextMove] = ROCK;
    return ROCK;
    }


    /**
    * Stores my previous move.
    */
    public void myMove () {
    myMove[nextMove - 1] = this.move();
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me solve this problem, this is really urgent!

    Are the methods calling each other continually, recursively until the exception?
    You will have to change the logic so they don't do that.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Please help me solve this problem, this is really urgent!

    Quote Originally Posted by KalvinL7 View Post
    Hey, can you please help me out, every time i try to run this code I get an error:
    "Exception in thread "Thread-5" java.lang.StackOverflowError
    at players.K4LV1N.myMove(K4LV1N.java:115)
    at players.K4LV1N.move(K4LV1N.java:86)"

    Basically the move() method is called once every match by the SLArena and I am trying to store the moves in an array using the myMove() method.
    Hello KalvinL7!
    java.lang.StackOverflowError is usually caused by recursive calling with no end of recursion. In your code in move() method you call myMove() method and in myMove() you "call" move() (this.move()).

Similar Threads

  1. help me to solve my problem
    By miszIna in forum Object Oriented Programming
    Replies: 3
    Last Post: February 14th, 2011, 09:40 AM
  2. Plz solve the problem
    By rasheedmgs in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: October 14th, 2010, 11:59 AM
  3. Questions about a Problem I'm trying to solve
    By DarkEssence in forum Java Theory & Questions
    Replies: 4
    Last Post: March 17th, 2010, 06:29 AM
  4. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM
  5. Replies: 2
    Last Post: May 16th, 2009, 05:23 AM