Computer Science Canada

Weird xlint error with my linkedlist adding method

Author:  gsquare567 [ Sat Dec 02, 2006 10:59 pm ]
Post subject:  Weird xlint error with my linkedlist adding method

check this:
code:

GalacticWar.java:975: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);

where getSprites() returns a LinkedList of type AnimatedSprite, and bullets[] is an array of animatedsprite. what could be the problem? ps, this is 28x plus another error... read here:
code:

C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\Asteroids\classes>javac
-Xlint GalacticWar.java
GalacticWar.java:157: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                getSprites().add(ship);
                                ^
GalacticWar.java:555: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                getSprites().add(ship);
                                ^
GalacticWar.java:599: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                getSprites().add(asteroid);
                                ^
GalacticWar.java:691: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                getSprites().add(asteroid);
                                ^
GalacticWar.java:708: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                getSprites().add(expl);
                                ^
GalacticWar.java:725: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                getSprites().add(expl);
                                ^
GalacticWar.java:792: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(powerup);
                                                ^
GalacticWar.java:799: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(powerup);
                                                ^
GalacticWar.java:806: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(powerup);
                                                ^
GalacticWar.java:813: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(powerup);
                                                ^
GalacticWar.java:820: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(powerup);
                                                ^
GalacticWar.java:827: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(powerup);
                                                ^
GalacticWar.java:920: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:926: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:930: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[1]);
                                                ^
GalacticWar.java:936: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:939: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[2]);
                                                ^
GalacticWar.java:943: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[2]);
                                                ^
GalacticWar.java:949: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:953: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[1]);
                                                ^
GalacticWar.java:957: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[2]);
                                                ^
GalacticWar.java:961: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[3]);
                                                ^
GalacticWar.java:967: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:971: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:975: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:979: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:983: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:987: warning: [unchecked] unchecked call to add(E) as a member
of the raw type java.util.LinkedList
                                getSprites().add(bullets[0]);
                                                ^
GalacticWar.java:8: warning: [serial] serializable class GalacticWar has no defi
nition of serialVersionUID
public class GalacticWar extends Game
       ^
29 warnings

Author:  wtd [ Sat Dec 02, 2006 11:51 pm ]
Post subject: 

Of you're using Java 1.5 and collections, you'll need to be familiar with generics.

Author:  gsquare567 [ Sat Dec 02, 2006 11:57 pm ]
Post subject: 

thanks for the help... now can anyone tell me why these are coming up?

Author:  OneOffDriveByPoster [ Sun Dec 03, 2006 12:29 am ]
Post subject: 

gsquare567 wrote:
thanks for the help... now can anyone tell me why these are coming up?

Check your method signature for getSprites(). wtd is right, get used to generics if you are using Java 1.5.

Author:  wtd [ Sun Dec 03, 2006 9:34 am ]
Post subject: 

We know of what we speak.

code:
import java.util.ArrayList;

public class Foo {
   public static void main(String[] args) {
      ArrayList arr = new ArrayList();
          int i = 5;
          
          arr.add(i);
   }
}


code:
$ javac -Xlint:unchecked Foo.java
Foo.java:8: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
          arr.add(i);
                 ^
1 warning


code:
import java.util.ArrayList;

public class Foo {
   public static void main(String[] args) {
      ArrayList<Integer> arr = new ArrayList<Integer>();
          int i = 5;
          
          arr.add(i);
   }
}


code:
$ javac -Xlint:unchecked Foo.java
$

Author:  gsquare567 [ Sun Dec 03, 2006 2:34 pm ]
Post subject: 

thanks, but it still doesn't work... heres how i declare the LinkedList:
code:

private LinkedList<AnimatedSprite> sprites;
sprites = new LinkedList<AnimatedSprite>();

and heres how i call it:
code:

public LinkedList getSprites()
        {
                return sprites;
        }

i still get the same message, and can you also look at the very last error, something about serialVersionUID?

Author:  OneOffDriveByPoster [ Sun Dec 03, 2006 4:30 pm ]
Post subject: 

Check the method signature; what is different from your declaration of sprites? Your code below:
Java:
private LinkedList<AnimatedSprite> sprites;
public LinkedList getSprites() { /* ... */ }

Re: serialVersionUID:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html

Author:  gsquare567 [ Sun Dec 03, 2006 6:32 pm ]
Post subject: 

OH NO WAY MAN U R GOD! public LinkedList<AnimatedSprite> getSprites()... your a genious!

Author:  gsquare567 [ Sun Dec 03, 2006 6:56 pm ]
Post subject: 

umm hmm... got rid of the "recompile with -Xlint", but now wen i run the internet file, the applet wont work. says "Loading Java Applet Failed"... i did everything required to run an applet, so why isnt it working?

Author:  gsquare567 [ Mon Dec 04, 2006 1:19 pm ]
Post subject: 

any1?

Author:  wtd [ Mon Dec 04, 2006 1:22 pm ]
Post subject: 

Which browser are you using?

Author:  gsquare567 [ Mon Dec 04, 2006 6:37 pm ]
Post subject: 

firefox, but it worked b4 for 2 other games. i even copied the htm file for the other two and just renamed it + the "code = " parameter

Author:  gsquare567 [ Mon Dec 04, 2006 10:07 pm ]
Post subject: 

heres another problem, might be connected... i cant make a jar file. heres the error message:
code:

C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\Asteroids\src\Version 3>
jar cvfm GalacticWar3.jar manifest.txt *.*
java.io.IOException: invalid header field
        at java.util.jar.Attributes.read(Attributes.java:389)
        at java.util.jar.Manifest.read(Manifest.java:167)
        at java.util.jar.Manifest.<init>(Manifest.java:52)
        at sun.tools.jar.Main.run(Main.java:123)
        at sun.tools.jar.Main.main(Main.java:903)

ps, i include a manifest called manifest.txt plus all the classes needed. the manifest is 3 lines, Main-Class: GalacticWar + 2 blank lines Very Happy

Author:  Aziz [ Tue Dec 05, 2006 9:10 am ]
Post subject: 

using generics would cause that problem, try and step back a few steps in your code (ie. undo a bit, then add in the <> bit). Also, make sure your browser has an up-to-date JRE plug-in installed. The latest is 6 (or 1.6) but that's a prerelease, so 5 (update 9) should be fine

Author:  gsquare567 [ Tue Dec 05, 2006 3:49 pm ]
Post subject: 

i based my entire game on the LinkedList which is where i store the sprites or objects on the screen... so i'll try downloading the latest plugin and update, i'll get back to you to tell you if it still doesnt work.

Author:  gsquare567 [ Tue Dec 05, 2006 4:03 pm ]
Post subject: 

nope, didnt work. still says "Applet GalacticWar notinited". i dled the jdk 5 update 10...

Author:  gsquare567 [ Wed Dec 06, 2006 7:16 pm ]
Post subject: 

BUMP...
and, added a lil info if it helps you solve this complex error Very Happy.

ok. i re-dled the whole jse and got update 10. heres the shiz lol:

HTML CODE

code:

<HTML>
<HEAD>
<TITLE>Galactic War - enhanced by Gsquare567</TITLE>
</HEAD>
<BODY>
<APPLET
        archive = "GalacticWar3.jar"
        code    = GalacticWar.class
        width   = "800"
        height  = "600"
        >
</APPLET>
</BODY>
</HTML>


FIRST LINES OF MAIN JAVA CODE

code:

public class GalacticWar extends Game

code:

abstract class Game extends Applet implements Runnable, KeyListener


MANIFEST FILE CODE
code:

Main-Class: GalacticWar



PS thanks a lot for helping me man. if you actually solve this problem... well... iunno i'll thank you. Confused

Author:  gsquare567 [ Thu Dec 07, 2006 8:06 pm ]
Post subject: 

whats with this wtd hasnt responded on the hour! is he sick or sumtin?

Author:  gsquare567 [ Sun Dec 10, 2006 2:32 pm ]
Post subject: 

anyone???

Author:  gsquare567 [ Wed Dec 13, 2006 9:57 pm ]
Post subject: 

ok, this is REALLY buggin me, so im just taking random guesses, hoping someone can help. so it says applet notinited, i thought, well maybe its the init method. well, here it is, i checked EVERYTHING i could, but there is something missing/incorrect. help! please!
code:
public void init()
        {
                backBuffer = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB);
                g2d = backBuffer.createGraphics();

                sprites = new LinkedList<AnimatedSprite>();

                addKeyListener(this);

                gameStartup();// implemented by subclass
        }

and here is the method implemented by the subclass.
code:
void gameStartup()
        {
                // load sounds and music
                music.load("music.midi");
                shoot.load("shoot.au");
                explosion.load("explode.au");

                // load the health/shield bars
                barFrame = new ImageEntity(this);
                barFrame.load("barframe.png");
                barImage[0] = new ImageEntity(this);
                barImage[0].load("bar_health.png");
                barImage[1] = new ImageEntity(this);
                barImage[1].load("bar_shield.png");

                // load powerups
                powerupShield = new ImageEntity(this);
                powerupShield.load("powerup_shield2.png");
                powerupHealth = new ImageEntity(this);
                powerupHealth.load("powerup_cola.png");
                powerup250 = new ImageEntity(this);
                powerup250.load("powerup_250.png");
                powerup500 = new ImageEntity(this);
                powerup500.load("powerup_500.png");
                powerup1000 = new ImageEntity(this);
                powerup1000.load("powerup_1000.png");
                powerupGun = new ImageEntity(this);
                powerupGun.load("powerup_gun.png");

                // load the background
                background = new ImageEntity(this);
                background.load("bluespace.png");

                // create the ship
                shipImage[0] = new ImageEntity(this);
                shipImage[0].load("spaceship.png");
                shipImage[1] = new ImageEntity(this);
                shipImage[1].load("ship_thrust.png");
                shipImage[2] = new ImageEntity(this);
                shipImage[2].load("ship_shield.png");

                AnimatedSprite ship = new AnimatedSprite(this, getGraphics());
                ship.setSpriteType(SPRITE_SHIP);
                ship.setImage(shipImage[0].getImage());
                ship.setFrameWidth(ship.getImageWidth());
                ship.setFrameHeight(ship.getImageHeight());
                ship.setPosition(new Point2D(SCREENWIDTH/2, SCREENWIDTH/2));
                ship.setAlive(true);
                ship.setState(STATE_EXPLODING);

                collisionTimer = System.currentTimeMillis();
                addToSprites(ship);

                // load the bullet
                bulletImage = new ImageEntity(this);
                bulletImage.load("plasmashot.png");

                // load the explosion
                explosions[0] = new ImageEntity(this);
                explosions[0].load("explosion.png");
                explosions[1] = new ImageEntity(this);
                explosions[1].load("explosion2.png");

                // load the asteroids
                for(int i = 0; i < 5; i++)
                {
                        bigAsteroids[i] = new ImageEntity(this);
                        bigAsteroids[i].load("asteroid" + (i+1) + ".png");
                }
                for(int i = 0; i < 2; i++)
                {
                        medAsteroids[i] = new ImageEntity(this);
                        medAsteroids[i].load("medium" + (i+1) + ".png");
                }
                for(int i = 0; i < 3; i++)
                {
                        smlAsteroids[i] = new ImageEntity(this);
                        smlAsteroids[i].load("small" + (i+1) + ".png");
                }
                for(int i = 0; i < 4; i++)
                {
                        tnyAsteroids[i] = new ImageEntity(this);
                        tnyAsteroids[i].load("tiny" + (i+1) + ".png");
                }

                // start in pause mode
                pauseGame();
        }


i checked that all files were written correctly, although i wasnt sure if a MIDI file's extension was mid or midi so i tried both, and neither worked, so i assume it doesnt matter. also, the au extension is for an AU file, and png is for PNG... so i know those are correct.
what could be the problem? just throw things PLEASE!

Author:  Neville [ Wed Dec 13, 2006 11:40 pm ]
Post subject: 

I would start by debugging as much as you can. Do you use an IDE with built in debugging? This way you could step through and see where it is failing. If not, try writing an output file with little messages to see how far along your init() goes before it fails. That way you can narrow down the problem. It's most likely an exception being thrown somewhere.


: