Results 1 to 5 of 5
- 10-02-2011, 07:42 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Need help with error: java.lang.ArrayIndexOutOfBoundsException: 1
Hey im fairly new to java only been programming for about a month now, and i was trying to make this program which would draw particles to the screen and then make them fall to the ground, unfortunately i got this error. Heres my code : -
Any kind of help would me much appreciated!Java Code:import java.awt.*; import hsa.Console; import java.util.*; public class Particles { static Console c; // The output console public static void main (String[] args) throws Exception { c = new Console (); int maxx = c.getWidth (); int maxy = c.getHeight (); int Max_Particles = 500; int[] [] coordinates = new int [199] [1]; int x = 0; int y = 0; for (int i = 0 ; i < 198 ; i++) { Random rand = new Random (); int random = 1 + rand.nextInt (500); int random2 = 1 + rand.nextInt (500); coordinates [i] [0] = random; random = x; coordinates [i] [1] = random2; random2 = y; } for (int particles = 0 ; particles < Max_Particles ; particles++) { c.drawOval (x, y + particles, 5, 10); Thread.sleep (100); if (y >= 500) ; { y = 0; } } // Place your program here. 'c' is the output console } // main method } // Particles class
Last edited by sunde887; 10-02-2011 at 07:49 PM. Reason: Added code tags, [code]...[/code]
- 10-02-2011, 07:48 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 10-02-2011, 07:50 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Re: Need help with error: java.lang.ArrayIndexOutOfBoundsException: 1
Oh so what do you suggest i should do to make it work and make multiple particles appear at once falling down on the screen?
Last edited by iowndd; 10-02-2011 at 07:57 PM.
- 10-02-2011, 08:09 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Need help with error: java.lang.ArrayIndexOutOfBoundsException: 1
I feel like you should make Particle an object, the class should represent one single particle (which contains the location). Then have an array of particles, which all have there own location. Perhaps each particle can have some deltaX/Y variables which control how it moves.
Also, a very nice tutorial which may give you a lot of ideas on how to implement this can be found here: http://www.dreamincode.net/forums/to...-game-of-pong/
Some suggestions if you actually try to make the pong as the tutorial goes through: draw instead with a bufferedImage, place it in a jpanel (standalone app rather than an applet). Generalize the paddle class so there is only one class. Fix the problem of using all the setters inside of constructors and setters. Instead simply assign the variables directly. Even if you don't try it, reading it should give you a good idea of how to put particles on the screen and animate them.Last edited by sunde887; 10-02-2011 at 08:12 PM.
- 10-02-2011, 08:29 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
java.lang.ArrayIndexOutOfBoundsException error
By MBD in forum New To JavaReplies: 1Last Post: 09-27-2011, 06:47 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
java.lang.ArrayIndexOutOfBoundsException
By mensa in forum Java 2DReplies: 7Last Post: 05-05-2008, 09:09 AM -
Error: java.lang.ArrayIndexOutOfBoundsException
By fernando in forum Java 2DReplies: 1Last Post: 07-31-2007, 11:47 PM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks