Results 1 to 5 of 5
  1. #1
    berkeley is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default why does this code keep freezing?

    public boolean keyDown (Event e, int key)
    {

    while (key == Event.LEFT)
    {
    if (key != Event.LEFT)
    {
    x_speed = 0;
    continue;
    }
    x_speed = -1;
    }


    while (key == Event.RIGHT)
    {


    if (key != Event.RIGHT)
    {
    x_speed = 0;
    continue;
    }
    x_speed = 1;
    }

    return true;
    }
    Last edited by berkeley; 06-03-2010 at 11:50 AM.

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    there is something wrong inside the while(true) loop. test the results inside the loop in the console before you run it as an applet.

  3. #3
    berkeley is offline Member
    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Default

    There is nothing wrong with that loop because it works when I don't have the other two whiles loops

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    How do you know that the code you posted is "freezing"?
    Add some println() as debug to show where and what is happening.

    Or just use paper and pencil to walk thru/desk check what happens in the code.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Inside the body of those while loops you never assign another value to your 'key' parameter so the condition of that while loop (that only depends on the value of that parameter) always succeeds and never terminates.

    kind regards,

    Jos

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2010, 12:19 PM
  2. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 02:21 PM
  3. Replies: 2
    Last Post: 03-16-2009, 03:33 PM
  4. freezing when use socket.accept() inside of a thread
    By tamayo in forum Advanced Java
    Replies: 0
    Last Post: 07-24-2007, 12:48 AM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •