1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Illegal Start of Expression Please Help

Discussion in 'Software Development' started by nichellek, Jan 2, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. nichellek

    nichellek Thread Starter

    Joined:
    Jan 2, 2011
    Messages:
    4
    Hi, I keep getting this illegal start of expression error, and I cannot figure out where to fix it.
    Any help would be greatly appreciated. It is the line "public void keyReleased(KeyEvent k) {}"


    /********************************************************
    *key listener events
    ******************************************************/
    public void keyReleased(KeyEvent k){}
    public void keyTyped(KeyEvent k){}
    public void keyPressed(KeyEvent k){

    int keyCode = k.getKeyCode();

    switch (keyCode)
    {
    case KeyEvent.VK_LEFT:
    //left arrow rotates ship left 5 degrees
    ship.incFaceAngle(-5);
    if (ship.getFaceAngle() > 0) ship.setFaceAngle(360-5);
    break;

    case KeyEvent.VK_RIGHT:
    //right arrow rotates ship right 5 degrees
    ship.incFaceAngle(5);
    if (ship.getFaceAngle() > 360) ship.setFaceAngle(5);
    break;

    case keyEvent.VK_UP:
    //up arrow adds thrust to ship (1/10 normal speed)
    ship.setMoveAngle(ship.getFaceAngle() -90);
    ship.incVelX(calcAngleMoveX(ship.getMoveAngle())*0.1);
    ship.incVelY(calcAngleMoveY(ship.getMoveAngle())*0.1);
    break;

    //Ctrl, Enter, or Space can be used to fire weapon
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_ENTER:
    case KeyEvent.VK_SPACE:
    //fire a bullet
    currentBullet++;
    if (currentBullet > BULLETS -1) currentBullet = 0;
    bullet[currentBullet].setAlive(true);

    //point bullet in same direction ship is facing
    bullet[currentBullet].setX(ship.getX());
    bullet[currentBullet].setY(ship.getY());
    bullet[currentBullet].setMoveAngle(ship.getFaceAngle()-90);

    //fire bullet at angle of the ship
    double angle = bullet[currentBullet].getMoveAngle();
    double svx = ship.getVelX();
    double svy = ship.getVelY();
    bullet[currentBullet].setVelX(svx + calcAngleMoveX(angle)*2);
    bullet[currentBullet].setVelY(svy + calcAngleMoveY(angle)*2);
    break;
    }
    }

    Thanks in advance!
     
  2. Senryi

    Senryi

    Joined:
    May 26, 2005
    Messages:
    75
    Probably a novice question on my part, but what programming language is this?
     
  3. nichellek

    nichellek Thread Starter

    Joined:
    Jan 2, 2011
    Messages:
    4
    java, this is a section of a larger class, but it is the only compiler error I am getting.
     
  4. Senryi

    Senryi

    Joined:
    May 26, 2005
    Messages:
    75
    I am guessing it doesn't like how to started the 'switch' function. I am guessing it is popping up because of incorrect syntax.
     
  5. nichellek

    nichellek Thread Starter

    Joined:
    Jan 2, 2011
    Messages:
    4
    What is incorrect with the syntax?
     
  6. Senryi

    Senryi

    Joined:
    May 26, 2005
    Messages:
    75
    Honestly it has been a few years since I worked in java, so I would need to look it up in order to be correct.

    I am just guessing that is what it has a problem with.
     
  7. JimmySeal

    JimmySeal

    Joined:
    Sep 25, 2007
    Messages:
    290
    If it's reporting that error on the keyReleased() line, then most likely the issue is somewhere before that line, not after it.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Illegal Start Expression
  1. damonreyes
    Replies:
    9
    Views:
    474
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/972130

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice