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 / First Aid / September 2006

Tip: Looking for answers? Try searching our database.

out of bounds exception

Thread view: 
ap - 05 Sep 2006 22:35 GMT
Hi all,
I've got a routine that initializes a 3-dimensional array in which
the sizes of the arrays are read in at run-time followed by the values.

I get the infamous array out of bounds exception. Anything wrong?
THANKS

public myType_T[][][] getData_T()
{

     myType_T[][][] avList={} ;
     int outerSize=0; int innerSize=0; int outerMostSize=0;

     // Get dimension of outermost sequence
     outerMostSize=getLength();

     log.info("number of outer most sequence elements " +
outerMostSize);

     if (outerMostSize==0)
     {
        return avList;
     }

     avList= new myType_T [outerMostSize][][];
     for (int i=0; i < outerMostSize; i++)
     {
        log.info("i= "+ i);
        outerSize=getLength();
        log.info("number of outer sequence elements " + outerSize);
        avList[i]=new NameAndStringValue_T[outerMostSize][outerSize];

        for (int j=0; j < outerSize; j++)
        {

            log.info("j= "+ j);
            innerSize =getLength();
            log.info("number of innermost sequence elements " +
innerSize);

            log.info("size of a[i][j] " + avList[i][j].length);
            avList[i][j]=new myType_T[innerSize];

            log.info("past new of innersize");

            for (int k=0; k < innerSize; k++) {
                  log.info("k= "+ k);
                  avList[i][j][k]=getmyType_T();
           }
        }  

     }
     return avList;
   
}
Andrew Thompson - 06 Sep 2006 06:28 GMT
...
>          avList[i]=new NameAndStringValue_T[outerMostSize][outerSize];

I suspect this needs to be..

           avList[i]=new NameAndStringValue_T[outerSize];

..if not, you might try wrapping that snippet in a few extra
lines and making it a compilable example, rather than
forcing the reader to 'guess' which of the three array
assignments is causing the problem.

Andrew T.


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.