Results 1 to 7 of 7

Thread: -Xlint???

  1. #1
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default -Xlint???

    When compiling my project i get this kind of message:
    "Note: rtype\Craft.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details."

    code is :
    Java Code:
    package rtype;
    
    import java.awt.Image;
    import java.awt.event.KeyEvent;
    
    import java.util.ArrayList;
    
    import javax.swing.ImageIcon;
    
    public class Craft {
    
        private String craft = "craft.png";
    
        private int dx;
        private int dy;
        private int x;
        private int y;
        private Image image;
    
        private ArrayList missiles;
    
        private final int CRAFT_SIZE = 20;
    
        public Craft() {
            ImageIcon ii = new ImageIcon(this.getClass().getResource(craft));
            image = ii.getImage();
            missiles = new ArrayList();
            x = 40;
            y = 60;
        }
    
    
        public void move() {
            x += dx;
            y += dy;
        }
    
        public int getX() {
            return x;
        }
    
        public int getY() {
            return y;
        }
    
        public Image getImage() {
            return image;
        }
    
        public ArrayList getMissiles() {
            return missiles;
        }
    
        public void keyPressed(KeyEvent e) {
    
            int key = e.getKeyCode();
    
            if (key == KeyEvent.VK_SPACE) {
                fire();
            }
    
            if (key == KeyEvent.VK_LEFT) {
                dx = -1;
            }
    
            if (key == KeyEvent.VK_RIGHT) {
                dx = 1;
            }
    
            if (key == KeyEvent.VK_UP) {
                dy = -1;
            }
    
            if (key == KeyEvent.VK_DOWN) {
                dy = 1;
            }
        }
    
        public void fire() {
            missiles.add(new Missile(x + CRAFT_SIZE, y + CRAFT_SIZE/2));
        }
    
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
    
            if (key == KeyEvent.VK_LEFT) {
                dx = 0;
            }
    
            if (key == KeyEvent.VK_RIGHT) {
                dx = 0;
            }
    
            if (key == KeyEvent.VK_UP) {
                dy = 0;
            }
    
            if (key == KeyEvent.VK_DOWN) {
                dy = 0;
            }
        }
    }
    Could someone tell me whatswrogn here?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: -Xlint???

    You're using a 'raw' type ArrayList and the compiler warns against it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: -Xlint???

    im following zetcode tutorial and there it says do it this way. What would be yor suggestion to fix it?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: -Xlint???

    Quote Originally Posted by vastrolorde View Post
    im following zetcode tutorial and there it says do it this way. What would be yor suggestion to fix it?
    Try another tutorial and in the mean time use a parameterized ArrayList<Missile> so your compiler knows about it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,950
    Rep Power
    4

    Default Re: -Xlint???

    From looking at your code, it should be

    Java Code:
      private ArrayList<Missile> missiles;  // since Java 1.5
        private final int CRAFT_SIZE = 20;
        public Craft() {
            ImageIcon ii = new ImageIcon(this.getClass().getResource(craft));
            image = ii.getImage();
            missiles = new ArrayList<Missile>();
            x = 40;
            y = 60;
        }
       ...
       
      public ArrayList<Missile> getMissiles() { 
           return missiles;
      }

    Regards,
    Jim
    Last edited by jim829; 03-08-2013 at 07:49 PM. Reason: too late again!!
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: -Xlint???

    Quote Originally Posted by jim829 View Post
    Last edited by jim829; Today at 07:49 PM. Reason: too late again!!
    Hah! Finally! Victory is mine! Someone is even slower than I am! I'm going to be famous and filthy stinking rich! And ample supplies of scantily clad women! and ... and ... sorry, 't won't happen again.

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

Similar Threads

  1. Replies: 24
    Last Post: 07-29-2011, 04:53 PM
  2. -Xlint / -Deprecation Error
    By seejay in forum New To Java
    Replies: 3
    Last Post: 01-14-2011, 11:25 PM
  3. xlint full form
    By java4susant in forum New To Java
    Replies: 0
    Last Post: 10-27-2010, 02:08 AM
  4. unchecked or unsafe operations-Recompile with -Xlint
    By pronetin in forum Advanced Java
    Replies: 15
    Last Post: 05-31-2010, 05:41 PM
  5. Xlint in build.xml not working
    By sunjavaboy in forum Eclipse
    Replies: 0
    Last Post: 06-23-2008, 01:35 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
  •