Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

ArrayOutOfBoundException when printing out a two dimension array

Thread view: 
Jason - 25 May 2005 18:32 GMT
hi, i have the following 2d array:
Object[][] data =
    {
        {new Boolean(false), "Mary", new Date(), "Snowboarding", new
Integer(5) },
        {new Boolean(true), "Alison", new Date(), "Rowing", new Integer(3) },
        {new Boolean(false), "Kathy", new Date(), "Knitting", new Integer(2)
},
        {new Boolean(true), "Sharon", new Date(), "Speed reading", new
Integer(20) },
        {new Boolean(false), "Philip", new Date(), "Pool", new Integer(10) }
    };

and the following method to print out a 2d array:
private static void prtArray(Object[][] array)
{
    for(int i = 0; i < array.length; i++)
    {
        System.out.println("");
        for(int y = 0; i < array[i].length; y++)
        {
            System.out.print(array[i][y] + ", ");
        }
    }
    System.out.println("---------------------------------------");
}

but when i invoke prtArray(data);, it gave me the following output:
false, Mary, Wed May 25 13:33:34 EDT 2005, Snowboarding, 5, Exception
in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Test.prtArray(Test.java:75) -- the line is:
System.out.print(array[i][y] + ", ");

anyone know what's wrong?
Roland - 25 May 2005 18:40 GMT
[snip]
>               for(int y = 0; i < array[i].length; y++)
                              *
probably should be:
                for(int y = 0; y < array[i].length; y++)
Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \

Locke - 25 May 2005 20:06 GMT
Exactly - it is always some mundane thing that causes the biggest problems.

Locke

> [snip]
>>               for(int y = 0; i < array[i].length; y++)
>                               *
> probably should be:
>                 for(int y = 0; y < array[i].length; y++)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.