Results 1 to 4 of 4
  1. #1
    Nelitzeb is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Help needed with simple program

    I need to write a simple program and when I try to run it, there's an error. Here's a screenshot:
    Help needed with simple program-problem.jpg

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Help needed with simple program

    Instead of simply posting a screenshot, if you want help, you're going to want to provide an SSCCE that demonstrates the problem, and you're going to want to copy and paste the full, exact text of the error message here. I'm not trying to be mean, but I can't really see the text in that image (I refuse to admit that I need glasses). Make it easier for people to help you.

    But here's a hint- What is the length of the array? What indexes does that mean it has? What index are you trying to access?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: Help needed with simple program

    ArrayIndexOutOfBounds error means that you tried to pass an index into an array which doesn't exist.

    For example, if I asked the program to give me the value for myArray[5] (index #5) but the array has only 4 items, when the program passes 5 into the array you will get this ArrayIndexOutOfBounds error.

    I can see that you are using a loop where the index is set to go through <= nL or nA; I havent tested your code but my first assumption would be that you should take out the "less than or equal to" and change it to "less than" so that the array index doesnt go out of bounds.

    EDIT: on second thoughts, you seem to be initializing a 2D array with [M][N] spaces... when you loop, make sure that you are looping LESS THAN those two values (M and N).
    Last edited by ozzyman; 12-14-2011 at 04:32 PM.

  4. #4
    Nelitzeb is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: Help needed with simple program

    I figured out the problem. My Math.random generated numbers from 0 to 16. I forgot that the indexes in an array with 16 elements go from 0 to 15, so my Math.random would eventually generate 16 and I got an error. :)

    Thanks for the help, I really appreciate it.

Similar Threads

  1. Simple program, simple problem
    By taymilll in forum New To Java
    Replies: 12
    Last Post: 06-20-2011, 06:12 AM
  2. Help needed very simple java program
    By pavez in forum New To Java
    Replies: 3
    Last Post: 08-22-2009, 04:05 PM
  3. Simple help needed
    By SaLiXeM in forum NetBeans
    Replies: 1
    Last Post: 12-12-2008, 10:13 AM
  4. Help Needed, simple jframe display
    By typh0n in forum New To Java
    Replies: 7
    Last Post: 10-03-2008, 02:06 AM
  5. Help needed writing a program...
    By Francis in forum New To Java
    Replies: 2
    Last Post: 11-22-2007, 03:03 PM

Posting Permissions

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