Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2015
    Rep Power

    Default While loop keeps crashing

    My program crashes every time I call this method because of the while loop. I guess its going into a infinite loop, but I cant figure out why. The game should keep running until the user ends it. Is the use of my .isKeyPressed correct and if so what else could it be?

    public static void run() {
    while (true) {

    if (StdDraw.isKeyPressed(KeyEvent.VK_Q)) {

    StdDraw.picture(250, 250, "space.jpg", 500, 500);

    Ship ship = new Ship();

    int x = ship.getShipPosx();
    int y = ship.getShipPosy();
    StdDraw.picture(x, y, "ship2.png", 40, 50);

    if (StdDraw.isKeyPressed(KeyEvent.VK_LEFT)) {
    ship.setShipPos(x - 10, y);

    if (StdDraw.isKeyPressed(KeyEvent.VK_RIGHT)) {
    ship.setShipPos(x + 10, y);



  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: While loop keeps crashing

    You haven't really posted sufficient code for anyone to be able help. Please provide a Short, Self Contained, Correct Example that demonstrates the problem.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Infinate Loop? (Crashing program)
    By kkid in forum New To Java
    Replies: 4
    Last Post: 10-02-2013, 10:22 PM
  2. Eclipse keeps crashing
    By oishi16 in forum Eclipse
    Replies: 1
    Last Post: 08-14-2012, 03:46 PM
  3. toast crashing my app
    By Drun in forum Android
    Replies: 2
    Last Post: 01-16-2012, 04:07 AM
  4. Crashing code
    By ke5awf in forum Advanced Java
    Replies: 2
    Last Post: 08-23-2011, 10:27 AM
  5. While loop crashing?
    By ToplessGrunt in forum New To Java
    Replies: 6
    Last Post: 10-20-2008, 11:07 AM

Posting Permissions

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