kuldip.kadam's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
16 (0.01 per day)
Joined:
23-February 11
Profile Views:
1,718
Last Active:
User is offline Sep 25 2012 03:53 AM
Currently:
Offline

Previous Fields

Country:
IN
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Icon   kuldip.kadam has not set their status

Posts I've Made

  1. In Topic: java.lang.ArrayIndexOutOfBoundsException

    Posted 9 Jul 2012

    jon.kiparsky could u please provide me with a solution to the problem?

    Thanks
  2. In Topic: java.lang.ArrayIndexOutOfBoundsException

    Posted 9 Jul 2012

    Below is the Exception:

    TRACE: <at java.lang.ArrayIndexOutOfBoundsException>, Exception caught in Display class
    java.lang.ArrayIndexOutOfBoundsException
    at java.util.Vector.removeElementAt(Vector.java:510)
    at o.a(), bci=399
    at o.c(), bci=71
    at f.a(), bci=2724
    at n.paint(), bci=224
    at javax.microedition.lcdui.CanvasLFImpl.uCallPaint(), bci=202
    at javax.microedition.lcdui.Display.callPaint(), bci=149
    at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleRepaintEvent(), bci=11
    at com.sun.midp.lcdui.RepaintEventProducer.process(), bci=55
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:662)

    Here is the code that is giving me that error.
    //@Author: Kuldip
    import java.util.Random;
    import java.util.Vector;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.game.Sprite;
    import javax.microedition.lcdui.Graphics;
    
    public class Obstacles {
    
        static public Image obst_airplane, 
                            obst_cloud_flat, 
                            obst_cloud_medium,
                            obst_cloud_small, 
                            obst_cloud_thinline, 
                            obst_ring,
                            obst_parachute,
                            obst_chocopack;
        
        static public Image airplane_collided,
                            cloudflat_collided, 
                            cloudmed_collided, 
                            cloudsmall_collided, 
                            cloudthin_collided,
                            ring_collided1,
                            ring_collided2,
                            parachute_collided;
        
        Vector obsCloudVec = new Vector();
        Vector obsRingVec = new Vector();
        Vector obsAirplaneVec = new Vector();
        Vector obsParachuteVec = new Vector();
        Vector obsChocopackVec = new Vector();
        
        Vector obsCloudcollidedVec = new Vector();
        Vector obsRingcollidedVec = new Vector();
        Vector obsAirplanecollidedVec = new Vector();
        Vector obsParachutecollidedVec = new Vector();
        //Vector<Integer> obstTypeVec;
        
        Sprite obstCloudSprite, obstCloudMovSprite,
                obstRingSprite, obstRingMovSprite,
                obstAirplaneSprite, obstAirplaneMovSprite,
                obstParachuteSprite, obstParachuteMovSprite,
                obstChocoPackSprite, obstChocoPackMovSprite;
        
        Sprite obstCloudcollidedSprite, obstCloudcollidedMovSprite,
                obstRingcollidedSprite, obstRingMovcollidedSprite,
                obstAirplanecollidedSprite, obstAirplanecollidedMovSprite,
                obstParachutecollidedSprite,obstParachutecollidedMovSprite;
        
        Sprite M_obstMovSprite;
        
        public int obstacles_type_cloud = 0, 
                    number_obst_type_cloud = 4;
        public int obstacles_type_cloudcollided = 0, 
                    number_obst_type_cloudcollided = 4;
        
        public int temp_HEIGHT, 
                    temp_WIDTH, 
                    parchuteY;
        
        public Random MyRandom;
        
        Sprite clouds[];
        Sprite cloudsCollided[];    
        
        Sprite ring;
        Sprite ringCollided;
        
        Sprite airplane;
        Sprite airplaneCollided;
        
        Sprite Parachute;
        Sprite ParachuteCollided;
        
        Sprite Chocopack;
        
        Vector vectorMovingCloudImg = new Vector();
        Vector vectorMovingRingImg = new Vector();
        Vector vectorMovingAirplaneImg = new Vector();
        Vector vectorMovingParachuteImg = new Vector();
        Vector vectorMovingChocoPackImg = new Vector();
        
        Vector vectorMovingCloudCollidedImg = new Vector();
        Vector vectorMovingRingCollidedImg = new Vector();
        Vector vectorMovingAirplaneCollidedImg = new Vector();
        Vector vectorMovingParachuteCollidedImg = new Vector();
        
        public int ring_collision, 
                    airplane_collision, 
                    cloud_collision,
                    cloudid, 
                    parachute_collision,
                    chocopack_collision;
        public int wrappercount,
                    collisioncount;
        
        boolean collision;
        
        GameScreen objGameScreen;
    
        public Obstacles(GameScreen objGameScreen) {
            this.objGameScreen=objGameScreen;
    
            initVariables_obstacles();
        }
    
        public void initVariables_obstacles() {
    
            CreateObstacles_Images();
    
            clouds = new Sprite[number_obst_type_cloud];
            cloudsCollided = new Sprite[number_obst_type_cloudcollided]; 
            
            ring_collision=0;
            airplane_collision=0;
            cloud_collision=0;
            parachute_collision=0;
            chocopack_collision=0;
            parchuteY=objGameScreen.HEIGHT-70;
            wrappercount=0;
            collisioncount=0;
            collision=true;
            
            MyRandom = new Random();
    
            
        }
    
        public void CreateObstacles_Images() {
            try {
                /*----------------before collision images-------------------*/
                obst_airplane = Image.createImage("/game/Airplane.png");
                obst_cloud_flat = Image.createImage("/game/cloud_flat.png");
                obst_cloud_medium = Image.createImage("/game/cloud_medium.png");
                obst_cloud_small = Image.createImage("/game/cloud_small.png");
                obst_cloud_thinline = Image.createImage("/game/cloud_thinline.png");
                obst_ring = Image.createImage("/game/ring.png");
                obst_parachute = Image.createImage("/game/parachute.png");
                obst_chocopack = Image.createImage("/game/chocopack.png"); 
             
                /*----------------after collision images-------------------*/
                airplane_collided = Image.createImage("/game/Airplane_Chocolaty.png");
                ring_collided1 = Image.createImage("/game/ring_Chocolaty1.png");
                ring_collided2 = Image.createImage("/game/ring_Chocolaty2.png");
                cloudflat_collided = Image.createImage("/game/cloud_flat_Chocolaty.png");
                cloudmed_collided = Image.createImage("/game/cloud_medium_Chocolaty.png");
                cloudsmall_collided = Image.createImage("/game/cloud_small_Chocolaty.png");
                cloudthin_collided = Image.createImage("/game/cloud_thinline_Chocolaty.png");
                parachute_collided = Image.createImage("/game/parachute_chocolaty.png");
                
            } catch (Exception e) {
                System.out.println("Exception in creating obstacle images...." + e);
            }
        }
        
        /*------------------------------------Collision Method--------------------------------------*/
         public void collision_with_obstacles(Image charImg, int chrXpos,
        int charYpos, Sprite obstImg, int obsXpos, int obsYpos, int obstType,int i) {
    
             //************* Ring collision detection **************
             if (obstType == 1) {
                 if (((chrXpos + charImg.getWidth()) - 30 >= obsXpos) && (chrXpos <= (obsXpos + obstImg.getWidth()) - 20)
                         && ((charYpos + charImg.getHeight()) - 50 >= obsYpos) && (charYpos <= (obsYpos + obstImg.getHeight()) - 10)) {
    
                     called_when_collided();
    
                     //vectorMovingRingImg.removeElementAt(i);
                     if (ring_collision <= 1) {
    
                         add_RingCollided1(obsXpos, obsYpos, i);
                         add_RingCollided2(obsXpos, obsYpos, i);
    
                     }
    
                 }
             }
             //********************Airplane collision detection***************
             if (obstType == 2) {
                 if (((chrXpos + charImg.getWidth()) - 20 >= obsXpos) && (chrXpos <= (obsXpos + obstImg.getWidth()) - 20)
                         && ((charYpos + charImg.getHeight()) - 40 >= obsYpos) && (charYpos <= (obsYpos + obstImg.getHeight()) + 10)) {
    
                     called_when_collided();
                     if (collision == true) {
                         if (airplane_collision == 1) {
                             if (collisioncount < 2) {
    
                                 collisioncount++;
    
                                 collision = false;
    
                             } else {
                                 //removeAllElements();
                                 objGameScreen.resetGame();
                             }
                         }
                     }
                     if (airplane_collision <= 1) {
    
                         /*try {*/
                             add_AirplaneCollided(obsXpos, obsYpos, i);
                        /* } catch (Exception e) {
                             System.out.println(" Exception 1 " + e);
                         }*/
    
                     }
                 }
    
             } //************************Cloud collision detection**********************
             else if (obstType == 3) {
                 if (((chrXpos + charImg.getWidth() - 5) >= obsXpos) && (chrXpos <= (obsXpos + obstImg.getWidth()))
                         && ((charYpos + charImg.getHeight()) >= obsYpos) && (charYpos <= (obsYpos + obstImg.getHeight()) + 20)) {
    
                     called_when_collided();
                     if (collision = true) {
                         if (cloud_collision == 1) {
                             if (collisioncount < 2) {
                                 collisioncount++;
    
                                 collision = false;
                             } else {
                                 // removeAllElements();
                                 objGameScreen.resetGame();
                             }
                         }
                     }
    
                     //vectorMovingCloudImg.removeElementAt(i);
                     if (cloud_collision <= 1) {
    
                        /* try {*/
                             add_CloudCollided(obsXpos, obsYpos, i, cloudid);
                         /*} catch (Exception e) {
                             System.out.println(" Exception 2 " + e);
                         }*/
    
                     }
                 }
    
             }
    
             //************************Parachute collision detection********************
             if (obstType == 4) {
                 if (((chrXpos + charImg.getWidth() - 20) >= obsXpos) && (chrXpos <= (obsXpos + obstImg.getWidth() - 20))
                         && ((charYpos + charImg.getHeight() - 30) >= obsYpos) && (charYpos <= (obsYpos + obstImg.getHeight()))) {
    
                     called_when_collided();
                     if (collision == true) {
                         if (parachute_collision == 1) {
                             if (collisioncount < 2) {
                                 collisioncount++;
                                 collision = false;
                             } else {
                                 //removeAllElements();
                                 objGameScreen.resetGame();
                             }
                         }
                     }
                     System.out.println("collided with parachute................");
                     //vectorMovingRingImg.removeElementAt(i);
                     if (parachute_collision <= 1) {
                         /*try {*/
                             add_ParachuteCollided(obsXpos, obsYpos, i);
                         /*} catch (Exception e) {
                             System.out.println(" Exception 3 " + e);
                         }*/
    
    
                     }
    
                 }
             }
    
             //************************ChocoPack collision detection********************
             if (obstType == 5) {
                 if (((chrXpos + charImg.getWidth() - 20) >= obsXpos) && (chrXpos <= (obsXpos + obstImg.getWidth()))
                         && ((charYpos + charImg.getHeight() - 20) >= obsYpos) && (charYpos <= (obsYpos + obstImg.getHeight() + 20))) {
                     wrappercount++;
                     called_when_collided();
                     System.out.println("collided with ChocoPack................");
                     if(objGameScreen.wrappercollided==false)
                     objGameScreen.wrappercollided=true;
                     if (chocopack_collision <= 1) {
                         
                         vectorMovingChocoPackImg.removeElementAt(i);
    
                     }
    
                 }
             }
    
        }
        
            
        public void removeAllElements(){
            /*obsCloudVec.removeAllElements();
            obsRingVec.removeAllElements();
            obsAirplaneVec.removeAllElements();
            obsParachuteVec.removeAllElements();
            obsChocopackVec.removeAllElements();*/
    
            obsCloudcollidedVec.removeAllElements();
            obsRingcollidedVec.removeAllElements();
            obsAirplanecollidedVec.removeAllElements();
            obsParachutecollidedVec.removeAllElements();
    
            vectorMovingCloudImg.removeAllElements() ;
            vectorMovingRingImg.removeAllElements() ;
            vectorMovingAirplaneImg.removeAllElements();
            vectorMovingParachuteImg.removeAllElements();
            vectorMovingChocoPackImg.removeAllElements();
    
            vectorMovingCloudCollidedImg.removeAllElements();
            vectorMovingRingCollidedImg.removeAllElements();
            vectorMovingAirplaneCollidedImg.removeAllElements();
            vectorMovingParachuteCollidedImg.removeAllElements();
            
        }
        
    
    
        public int randomCloudObstacles() {
    
            obstacles_type_cloud = (int) (Math.abs(MyRandom.nextInt() % number_obst_type_cloud));
            obstacles_type_cloudcollided = (int) (Math.abs(MyRandom.nextInt() % number_obst_type_cloudcollided));
                 
            return obstacles_type_cloud;
        }
    
        public void addCloudObstacles() {
            // temp_HEIGHT = GameView.temp_HEIGHT;
            // temp_WIDTH = GameView.temp_WIDTH;
    
            //	if(!obstTypeVec.isEmpty())
            //obstTypeVec.removeAllElements();
    
            switch (randomCloudObstacles()) {
    
                case 1:
                    obstCloudSprite = new Sprite(obst_cloud_flat, temp_WIDTH + obst_cloud_flat.getWidth(), temp_HEIGHT - obst_cloud_flat.getHeight());
                    obsCloudVec.addElement(obstCloudSprite);
                    //obstTypeVec.addElement(2);
                    break;
                case 2:
                    obstCloudSprite = new Sprite(obst_cloud_medium, temp_WIDTH + obst_cloud_medium.getWidth(), temp_HEIGHT - obst_cloud_medium.getHeight());
                    obsCloudVec.addElement(obstCloudSprite);
                    //obstTypeVec.addElement(3);
                    break;
                case 3:
                    obstCloudSprite = new Sprite(obst_cloud_small, temp_WIDTH + obst_cloud_small.getWidth(), temp_HEIGHT - obst_cloud_small.getHeight());
                    obsCloudVec.addElement(obstCloudSprite);
                    //obstTypeVec.addElement(4);
                    break;
                case 4:
                    obstCloudSprite = new Sprite(obst_cloud_thinline, temp_WIDTH + obst_cloud_thinline.getWidth(), temp_HEIGHT - obst_cloud_thinline.getHeight());
                    obsCloudVec.addElement(obstCloudSprite);
                    //obstTypeVec.addElement(4);
                    break;
    
    
                default:
                    obstCloudSprite = new Sprite(obst_cloud_small, temp_WIDTH+ obst_cloud_small.getWidth(), temp_HEIGHT - obst_cloud_small.getHeight());
                    obsCloudVec.addElement(obstCloudSprite);
                    break;
            }
    
        }
        public void addCloudCollidedObstacles() {
            // temp_HEIGHT = GameView.temp_HEIGHT;
            // temp_WIDTH = GameView.temp_WIDTH;
    
            //	if(!obstTypeVec.isEmpty())
            //obstTypeVec.removeAllElements();
    
            switch (randomCloudObstacles()) {
    
                case 1:
                    obstCloudcollidedSprite = new Sprite(cloudflat_collided, temp_WIDTH + cloudflat_collided.getWidth(), temp_HEIGHT - cloudflat_collided.getHeight());
                    obsCloudVec.addElement(obstCloudcollidedSprite);
                    //obstTypeVec.addElement(2);
                    break;
                case 2:
                    obstCloudcollidedSprite = new Sprite(cloudmed_collided, temp_WIDTH + cloudmed_collided.getWidth(), temp_HEIGHT - cloudmed_collided.getHeight());
                    obsCloudVec.addElement(obstCloudcollidedSprite);
                    //obstTypeVec.addElement(3);
                    break;
                case 3:
                    obstCloudSprite = new Sprite(cloudsmall_collided, temp_WIDTH + cloudsmall_collided.getWidth(), temp_HEIGHT - cloudsmall_collided.getHeight());
                    obsCloudVec.addElement(obstCloudcollidedSprite);
                    //obstTypeVec.addElement(4);
                    break;
                case 4:
                    obstCloudSprite = new Sprite(cloudthin_collided, temp_WIDTH + cloudthin_collided.getWidth(), temp_HEIGHT - cloudthin_collided.getHeight());
                    obsCloudVec.addElement(obstCloudcollidedSprite);
                    //obstTypeVec.addElement(4);
                    break;
    
    
                default:
                    obstCloudSprite = new Sprite(cloudsmall_collided, temp_WIDTH + cloudsmall_collided.getWidth(), temp_HEIGHT - cloudsmall_collided.getHeight());
                    obsCloudVec.addElement(obstCloudcollidedSprite);
                    break;
            }
    
        }
        
    
        public void addRingObstacle() {
            obstRingSprite = new Sprite(obst_ring, temp_WIDTH + obst_ring.getWidth(), temp_HEIGHT - obst_ring.getHeight());
            obsRingVec.addElement(obstRingSprite);
    
        }
        public void addRingCollidedObstacle() {
            obstRingcollidedSprite = new Sprite(ring_collided1, temp_WIDTH + obst_ring.getWidth(), temp_HEIGHT - obst_ring.getHeight());
            obsRingVec.addElement(obstRingSprite);
    
        }
        public void addAirplaneObstacle() {
            obstAirplaneSprite = new Sprite(obst_airplane, temp_WIDTH + obst_airplane.getWidth(), temp_HEIGHT - obst_airplane.getHeight());
            obsAirplaneVec.addElement(obstAirplaneSprite);
            
    
        }
        
        public void addAirplaneCollidedObstacle() {
            obstAirplanecollidedSprite = new Sprite(airplane_collided, temp_WIDTH + airplane_collided.getWidth(), temp_HEIGHT - airplane_collided.getHeight());
            obsAirplaneVec.addElement(obstAirplanecollidedSprite);
    
        }
        
        public void addParachuteObstacle(){
            obstParachuteSprite = new Sprite(obst_parachute, temp_WIDTH + obst_parachute.getWidth(), temp_HEIGHT - obst_parachute.getHeight());
            obsParachuteVec.addElement(obstParachuteSprite);
            
        }
        
        public void addParachuteCollidedObstacle() {
            obstParachutecollidedSprite = new Sprite(parachute_collided, temp_WIDTH + parachute_collided.getWidth(), temp_HEIGHT - parachute_collided.getHeight());
            obsParachuteVec.addElement(obstParachutecollidedSprite);
    
        }
        
        public void addChocoPackObstacle(){
            obstChocoPackSprite = new Sprite(obst_chocopack, temp_WIDTH + obst_chocopack.getWidth(), temp_HEIGHT - obst_chocopack.getHeight());
            obsChocopackVec.addElement(obstChocoPackSprite);
            
        }
    
        public void moveCloudObstacles() {
            for (int i = 0; i < obsCloudVec.size(); i++) {
                obstCloudMovSprite = (Sprite) obsCloudVec.elementAt(i);
                obstCloudMovSprite.move(-15, 20);
            }
    
            if (obsCloudVec.isEmpty()) {
                addCloudObstacles();
            }
        }
        public void moveCloudCollidedObstacles() {
            for (int i = 0; i < obsCloudVec.size(); i++) {
                obstCloudMovSprite = (Sprite) obsCloudVec.elementAt(i);
                obstCloudMovSprite.move(-15, 20);
            }
            
    
            if (obsCloudVec.isEmpty()) {
                addCloudCollidedObstacles();
            }
        }
    
        public void moveRingObstacles() {
            for (int i = 0; i < obsRingVec.size(); i++) {
                obstRingMovSprite = (Sprite) obsRingVec.elementAt(i);
                obstRingMovSprite.move(-15, 20);
            }
    
            if (obsRingVec.isEmpty()) {
                addRingObstacle();
            }
    
        }
        
        public void moveAirplaneObstacles() {
            for (int i = 0; i < obsAirplaneVec.size(); i++) {
                obstAirplaneMovSprite = (Sprite) obsAirplaneVec.elementAt(i);
                obstAirplaneMovSprite.move(-15, 20);
            }
    
            if (obsAirplaneVec.isEmpty()) {
                addAirplaneObstacle();
            }
    
        }
        
        public void moveAirplaneCollisionObstacles() {
            for (int i = 0; i < obsAirplaneVec.size(); i++) {
                obstAirplanecollidedMovSprite = (Sprite) obsAirplaneVec.elementAt(i);
                obstAirplanecollidedMovSprite.move(-15, 20);
            }
    
            if (obsAirplaneVec.isEmpty()) {
                addAirplaneCollidedObstacle();
            }
    
        }
        
        public void moveParachuteObstacles() {
            for (int i = 0; i < obsParachuteVec.size(); i++) {
                obstParachuteMovSprite = (Sprite) obsParachuteVec.elementAt(i);
                obstParachuteMovSprite.move(-15, 20);
            }
    
            if (obsParachuteVec.isEmpty()) {
                addParachuteObstacle();
            }
    
        }
        
        public void moveChocoPackObstacles() {
            for (int i = 0; i < obsChocopackVec.size(); i++) {
                obstChocoPackMovSprite = (Sprite) obsChocopackVec.elementAt(i);
                obstChocoPackMovSprite.move(-15, 20);
            }
    
            if (obsChocopackVec.isEmpty()) {
                addChocoPackObstacle();
            }
    
        }
    
        public void drawObstacles(Graphics canvas) {
    
            System.out.println("RANDOM NUMBER : " + randomCloudObstacles());
             }
        /*--------------------to generate random number----------------------*/
        private static int showRandomInteger(int aStart, int aEnd, Random aRandom) {
    
            int range = (int) aEnd - (int) aStart + 1;
            int fraction = (int) (Math.abs(aRandom.nextInt() % range));
            int randomNumber = (int) (fraction + aStart);
            return randomNumber;
    
        }
    
        public void addCloud(int type) {
            switch (type) {
                /*case 0:
                clouds[0] = new Sprite(obst_cloud_big);
                clouds[0].setPosition(240, 25);
                vectorMovingCloudImg.addElement(clouds[0]);
                
                break;*/
                case 0:
                    cloudid=0;
                    clouds[0] = new Sprite(obst_cloud_flat);
                    clouds[0].setPosition(240, 25);
                    vectorMovingCloudImg.addElement(clouds[0]);
                    break;
                case 1:
                    cloudid=1;
                    clouds[1] = new Sprite(obst_cloud_medium);
                    clouds[1].setPosition(240, 25);
                    vectorMovingCloudImg.addElement(clouds[1]);
                    break;
                case 2:
                    cloudid=2;
                    clouds[2] = new Sprite(obst_cloud_small);
                    clouds[2].setPosition(240, 30);
                    vectorMovingCloudImg.addElement(clouds[2]);
                    break;
                case 3:
                    cloudid=3;
                    clouds[3] = new Sprite(obst_cloud_thinline);
                    clouds[3].setPosition(240, 25);
                    vectorMovingCloudImg.addElement(clouds[3]);
                    break;
            }
    
            System.out.println("MyRandom......." + MyRandom);
    
        }
        public void add_CloudCollided(int x,int y,int i,int type) {   
            cloud_collision++;
            switch (type) {
                /*case 0:
                clouds[0] = new Sprite(obst_cloud_big);
                clouds[0].setPosition(240, 25);
                vectorMovingCloudImg.addElement(clouds[0]);
                
                break;*/
                case 0:
                    
                    cloudsCollided[0] = new Sprite(cloudflat_collided);
                    cloudsCollided[0].setPosition(x, y);
                    vectorMovingCloudImg.removeElementAt(i);
                    vectorMovingCloudImg.insertElementAt(cloudsCollided[0],i);
                    break;
                case 1:
                    cloudid=1;
                    cloudsCollided[1] = new Sprite(cloudmed_collided);
                    cloudsCollided[1].setPosition(x, y);
                    vectorMovingCloudImg.removeElementAt(i);
                    vectorMovingCloudImg.insertElementAt(cloudsCollided[1],i);
                    break;
                case 2:
                    cloudid=2;
                    cloudsCollided[2] = new Sprite(cloudsmall_collided);
                    cloudsCollided[2].setPosition(x, y);
                    vectorMovingCloudImg.removeElementAt(i);
                    vectorMovingCloudImg.insertElementAt(cloudsCollided[2],i);
                    break;
                case 3:
                    cloudid=3;
                    cloudsCollided[3] = new Sprite(cloudthin_collided);
                    cloudsCollided[3].setPosition(x, y);
                    vectorMovingCloudImg.removeElementAt(i);
                    vectorMovingCloudImg.insertElementAt(cloudsCollided[3],i);
                    break;
            }
            
            
            
            //System.out.println("airplane collided called.........2");
    
        }
    
        
    
        public void add_Ring() {
    
    
            ring = new Sprite(obst_ring);
            ring.setPosition(240, showRandomInteger(50, 150, MyRandom));
            vectorMovingRingImg.addElement(ring);
    
        }
        public void add_RingCollided1(int x,int y,int i) {
           // System.out.println("airplane collided called.........1");
    
            ring_collision++;
            ringCollided= new Sprite(ring_collided1);
            ringCollided.setPosition(x,y);
            vectorMovingRingImg.removeElementAt(i);
            vectorMovingRingImg.insertElementAt(ringCollided,i);
            //System.out.println("airplane collided called.........2");
    
        }
        public void add_RingCollided2(int x,int y,int i) {
           // System.out.println("airplane collided called.........1");
    
            ring_collision++;
            ringCollided= new Sprite(ring_collided2);
            ringCollided.setPosition(x+18,y);
            //vectorMovingRingImg.removeElementAt(i);
            vectorMovingRingImg.insertElementAt(ringCollided,i);
            //System.out.println("airplane collided called.........2");
    
        }
        
        public void add_Airplane() {
    
    
            airplane = new Sprite(obst_airplane);
            airplane.setPosition(240, showRandomInteger(50, 120, MyRandom));
            vectorMovingAirplaneImg.addElement(airplane);
    
        }
        
        public void add_AirplaneCollided(int x,int y,int i) {
           // System.out.println("airplane collided called.........1");
    
            airplane_collision++;
            airplaneCollided = new Sprite(airplane_collided);
            airplaneCollided.setPosition(x,y);
            vectorMovingAirplaneImg.removeElementAt(i);
            vectorMovingAirplaneImg.insertElementAt(airplaneCollided,i);
            //System.out.println("airplane collided called.........2");
    
        }
        
        public void add_Parachute() {
    
    
            Parachute = new Sprite(obst_parachute);
            Parachute.setPosition(350, showRandomInteger(200, 320, MyRandom));
            vectorMovingParachuteImg.addElement(Parachute);
    
        }
        
        public void add_ParachuteCollided(int x,int y,int i) {
           // System.out.println("airplane collided called.........1");
    
            parachute_collision++;
            ParachuteCollided= new Sprite(parachute_collided);
            ParachuteCollided.setPosition(x,y);
            vectorMovingParachuteImg.removeElementAt(i);
            vectorMovingParachuteImg.insertElementAt(ParachuteCollided,i);
            //System.out.println("airplane collided called.........2");
    
        }
        
        public void add_ChocoPack() {
    
    
            Chocopack = new Sprite(obst_chocopack);
            Chocopack.setPosition(1700, showRandomInteger(50, 120, MyRandom));
            vectorMovingChocoPackImg.addElement(Chocopack);
    
        }
        
        public void add_ChocopackCollided(int x,int y,int i) {
           // System.out.println("airplane collided called.........1");
    
            chocopack_collision++;
            Chocopack.setPosition(x, y);
            
            vectorMovingChocoPackImg.removeElementAt(i);
            
            
            //System.out.println("airplane collided called.........2");
    
        }
    
        public void move_clouds() {
            // System.out.println(" vectorMvngImg.size() " + vectorMovingCloudImg.size());
            for (int i = 0; i < vectorMovingCloudImg.size(); i++) {
                Sprite HitTypeSP1 = (Sprite) vectorMovingCloudImg.elementAt(i);
                HitTypeSP1.move(-3, 0);
                if (HitTypeSP1.getX() < -(HitTypeSP1.getWidth() + 10)) {
                    
                    vectorMovingCloudImg.removeElementAt(i);
                    // addCloud(randomCloudObstacles());
                    cloud_collision=0;
                    
                        //collision=true;
                
            }
            if (vectorMovingCloudImg.size() < 1) {
                addCloud(randomCloudObstacles());
            }
        }
        }
    
        public void move_ring() {
            for (int i = 0; i < vectorMovingRingImg.size(); i++) {
                Sprite HitTypeSP1 = (Sprite) vectorMovingRingImg.elementAt(i);
                HitTypeSP1.move(-7, 0);
                if (HitTypeSP1.getX()+1000 < -(HitTypeSP1.getWidth() + 10)) {
                    vectorMovingRingImg.removeElementAt(i);
                    ring_collision=0;
                    collision=true;
                }
    
            }
    
            if (vectorMovingRingImg.size() < 1) {
                add_Ring();
            }
    
        }
        
        public void move_Airplane() {
            for (int i = 0; i < vectorMovingAirplaneImg.size(); i++) {
                Sprite HitTypeSP1 = (Sprite) vectorMovingAirplaneImg.elementAt(i);
                HitTypeSP1.move(-18,0);//(-18,0)
                if (HitTypeSP1.getX()+1000 < -(HitTypeSP1.getWidth() )) {
                    vectorMovingAirplaneImg.removeElementAt(i);
                    airplane_collision=0;
                    
                        //collision=true;
                }
    
            }
    
            if (vectorMovingAirplaneImg.size() < 1) {
                add_Airplane();
            }
    
        }
        
        public void move_parachute() {
            for (int i = 0; i < vectorMovingParachuteImg.size(); i++) {
                Sprite HitTypeSP1 = (Sprite) vectorMovingParachuteImg.elementAt(i);
                HitTypeSP1.move(-11, -showRandomInteger(1, 9, MyRandom)); //(-11, -showRandomInteger(1, 9, MyRandom))
                if (HitTypeSP1.getX()+1400 < -(HitTypeSP1.getWidth() )) {
                    vectorMovingParachuteImg.removeElementAt(i);
                    parachute_collision=0;
                    
                        //collision=true;
                }
    
            }
    
            if (vectorMovingParachuteImg.size() < 1) {
                add_Parachute();
            }
    
        }
    
        public void move_ChocoPack() {
            for (int i = 0; i < vectorMovingChocoPackImg.size(); i++) {
                Sprite HitTypeSP1 = (Sprite) vectorMovingChocoPackImg.elementAt(i);
                HitTypeSP1.move(-7, 0);
                if (HitTypeSP1.getX()+1400 < -(HitTypeSP1.getWidth() )) {
                    vectorMovingChocoPackImg.removeElementAt(i);
                    chocopack_collision=0;
                    collision=true;
                }
    
            }
    
            if (vectorMovingChocoPackImg.size() <1) {
               
                add_ChocoPack();
            }
    
        }
        
        public void draw_cloud(Graphics g) {
    
            for (int i = 0; i < vectorMovingCloudImg.size(); i++) {
                Sprite HitTypeSP2 = (Sprite) vectorMovingCloudImg.elementAt(i);
                HitTypeSP2.paint(g);
                collision_with_obstacles(objGameScreen.imgBall[0], objGameScreen.cannonball.cannonballX, objGameScreen.cannonball.cannonballY, HitTypeSP2,  HitTypeSP2.getX(), HitTypeSP2.getY(),3,i);
    
            }
    
    
        }
    
        public void draw_ring(Graphics g) {
            for (int i = 0; i < vectorMovingRingImg.size(); i++) {
                Sprite HitTypeSP2 = (Sprite) vectorMovingRingImg.elementAt(i);
                HitTypeSP2.paint(g);
                collision_with_obstacles(objGameScreen.imgBall[0], objGameScreen.cannonball.cannonballX, objGameScreen.cannonball.cannonballY, HitTypeSP2,  HitTypeSP2.getX(), HitTypeSP2.getY(),1,i); 
    
            }
            
            }
        
        
        public void draw_Airplane(Graphics g) {
            for (int i = 0; i < vectorMovingAirplaneImg.size(); i++) {
                Sprite HitTypeSP2 = (Sprite) vectorMovingAirplaneImg.elementAt(i);
                HitTypeSP2.paint(g);
                collision_with_obstacles(objGameScreen.imgBall[0], objGameScreen.cannonball.cannonballX, objGameScreen.cannonball.cannonballY, HitTypeSP2,  HitTypeSP2.getX(), HitTypeSP2.getY(),2,i);
    
            }
        }
        
        public void draw_Parachute(Graphics g) {
            for (int i = 0; i < vectorMovingParachuteImg.size(); i++) {
                Sprite HitTypeSP2 = (Sprite) vectorMovingParachuteImg.elementAt(i);
                HitTypeSP2.paint(g);
                collision_with_obstacles(objGameScreen.imgBall[0], objGameScreen.cannonball.cannonballX, objGameScreen.cannonball.cannonballY, HitTypeSP2,  HitTypeSP2.getX(), HitTypeSP2.getY(),4,i);
    
            }
        }
        
        public void draw_ChocoPack(Graphics g) {
            for (int i = 0; i < vectorMovingChocoPackImg.size(); i++) {
                Sprite HitTypeSP2 = (Sprite) vectorMovingChocoPackImg.elementAt(i);
                HitTypeSP2.paint(g);
                collision_with_obstacles(objGameScreen.imgBall[0], objGameScreen.cannonball.cannonballX, objGameScreen.cannonball.cannonballY, HitTypeSP2,  HitTypeSP2.getX(), HitTypeSP2.getY(),5,i);
    
            }
        }
        
    
        public void called_when_collided() {
            
            
            
            
            
        }
    }
    
    
    
  3. In Topic: java.lang.ArrayIndexOutOfBoundsException

    Posted 9 Jul 2012

    I have caught the exception below in a try catch block

    //********************Airplane collision detection***************

    //************************Cloud collision detection**********************

    //************************Parachute collision detection********************

My Information

Member Title:
New D.I.C Head
Age:
25 years old
Birthday:
May 6, 1988
Gender:
Years Programming:
1
Programming Languages:
Java, J2ME

Contact Information

E-mail:
Private
Yahoo:
Yahoo  kuldip_kadam6@yahoo.com
Facebook:
http://www.facebook.com/kuldip.kadam

Comments

kuldip.kadam has no profile comments yet. Why not say hello?