Results 1 to 3 of 3
  1. #1
    Fortu is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Missing return statement error.

    SOLVED

    If you guys could help me figure out why I continue to get a "missing return statement" error at line 69, it would be a great help.


    Java Code:
    import javax.swing.ImageIcon;
    import java.awt.Image;
    import java.awt.event.KeyEvent;
    import java.util.ArrayList;
    
    
    public class Playuh
    {
    
      public Image image;
      public int x = 40;
      public int y = 465/2;
      public int movex;
      public int movey;
      public ArrayList<Shot> list;
    
      Playuh()
      {
        ImageIcon ii = new ImageIcon(this.getClass().getResource("Foot.png"));
        image = ii.getImage();
        list = new ArrayList<Shot>();
      }
    
      public Image getImage()
      {
        return image;
      }
    
      public int getX()
      {
        return x;
      }
    
      public int getY()
      {
        return y;
      }
    
      public void move()
      {
        x=x+movex;
        y=y+movey;
        if(x<0)
        {
          x=1;
        }
        if(x>558)
        {
          x=558;
        }
        if(y<1)
        {
          y=1;
        }
        if(y>407)
        {
          y=407;
        }
      }
    
      public ArrayList getShot()
      {
        return list;
      }
    
      public Shot fire()
      {
        list.add(new Shot(x+40, y + 50));
      }                                                    //   LINE 69 HERE.
    
    
      public void keyPressed(KeyEvent e)
      {
    
        int key = e.getKeyCode();
    
    
        if (key == KeyEvent.VK_LEFT)
        {
          movex=-1;
        }
    
    
        if (key == KeyEvent.VK_RIGHT)
        {
          movex=1;
        }
    
    
        if(key==KeyEvent.VK_UP)
        {
          movey=-1;
        }
    
    
        if (key == KeyEvent.VK_DOWN)
        {
          movey=1;
        }
    
        if (key == KeyEvent.VK_SPACE)
        {
          fire();
        }
      }
    
    
      public void keyReleased(KeyEvent e)
      {
    
        int key2 = e.getKeyCode();
    
        if(key2 == KeyEvent.VK_LEFT)
        {
          movex=0;
        }
    
    
        if(key2 == KeyEvent.VK_RIGHT)
        {
          movex=0;
        }
    
    
        if(key2 == KeyEvent.VK_UP)
        {
          movey=0;
        }
    
    
        if(key2 == KeyEvent.VK_DOWN)
        {
          movey=0;
        }
      }
    }
    Last edited by Fortu; 12-20-2010 at 12:33 AM. Reason: Specified where the error occurred

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Java Code:
      public Shot fire()
      {
        list.add(new Shot(x+40, y + 50));
      }
    you dont return a Shot ! change Shot to void if you dont want to return anything, or return the Shot which you are adding into the list ?!
    Last edited by eRaaaa; 12-11-2010 at 10:19 PM.

  3. #3
    Fortu is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    Oh, yeah, I didn't mean to return a Shot at all. Thank you for catching my mistake for me :D

Similar Threads

  1. missing return statement
    By bayan in forum New To Java
    Replies: 6
    Last Post: 04-26-2010, 04:15 PM
  2. Missing Return Statement Error
    By darkblue24 in forum New To Java
    Replies: 13
    Last Post: 02-16-2010, 09:22 PM
  3. Replies: 5
    Last Post: 01-17-2010, 12:14 AM
  4. Replies: 18
    Last Post: 12-02-2009, 01:01 PM
  5. Missing Return Statement error
    By anilanar in forum New To Java
    Replies: 2
    Last Post: 08-20-2009, 02:02 AM

Tags for this Thread

Posting Permissions

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