Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

maximum array size in applet

 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the maximum size of a array in java applet?
I want to define a very big array,for example: int data[1728000][3] in my applet, then read data from ASCII file into this array, then draw three lines accoring to this array, is it possible?
I tested a smaller array first: int data[72000][3], then tried to draw a three lines in canvas according to this data array. I checked data[][] array, I have got all the data inside the data[][], but when I drew, I only got one line, then I got the error message: arrayindexoutofboundexception:72000 and a lot of other error?
What to do with these? Thanks for your help!!
 
eammon bannon
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In theory I suppose array size is only limited by the maximum size you can define the array to be, in which case that is the max size an integer can be in Java. Since you get a 32-bit two's compliment number to use then this is 2147483647 - way bigger than 1728000. I would suspect though that creating such a big array would have significant performance issues, especially in an applet. I'd have a look at the BufferedReaders available in java.io for your requirements.
That aside, your problem is not to do with running out of space in an array. An ArrayIndexOutOfBoundException occurs when you try to reference an array element which is beyond the bounds of the defined array. e.g.

Remember that arrays are indexed from 0 not 1. So the maximum index in your 2D array is data[71999][2], and you seem to be asking for the 72000 element.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic