JCreater compiler error: "CODE TOO LARGE&quot

Yes, that’s right, “code too large” . I created a RandomGenerator class to spit out random numbers when i needed them, out of a giant int array so that whenever I run the game the random numbers generated are the same and the world created semi-randomly will not change whenever the game is loaded. My int array of 1 million was initialized entirely in the java code. But what happens when I try to compile? Two errors: “code too large” and “too many constants.” OK, so maybe hard-coding 1 million ints into an array was overkill (but no, I did not type them in by hand, I’m not insane), so I shortened it to 10,000. But I still get the “code too large” error even though the .java file has decreased from over 100,000 to barely 1,000 lines of code. Can’t I somehow set “COMPILE NO MATTER WHAT” as an option somewhere in JCreator? anyone?

That is interesting…

Well, after searching on the net, I found this post:
http://lists.bluej.org/pipermail/bluej-discuss/2003-August/002778.html

It says that methods may not be larger than 64K. So break it up into smaller methods. Or can’t you do a for loop?


for(i=0; i<array length; i++)
   array[i]=random number;

or something like that?

Take a look at java.util.Random.

[quote]I created a RandomGenerator class to spit out random numbers when i needed them, out of a giant int array so that whenever I run the game the random numbers generated are the same and the world created semi-randomly will not change whenever the game is loaded.
[/quote]
There’s absolutely no need to do that. You’re being thrown off by the definition of random. While algorithms do exist to generate true random numbers, they are generally time consuming and not suitable for real time applications. Because of this, most algorithms in common use (java.util.Random, implementations of rand() in C/C++, Marsenne Twister, etc) are actually pseudo-random.

In essence what this means is that if you use the same value to seed the algorithm, you will end up with the same sequence of numbers each time. This is a common cause of confusion. Anyway, all you need to do is to store the seed you initially used, and when you load the data later use that value to seed an instance of Random. Then you eliminate the need for your large array.

Yes but I prefer the illusion of being in control ;D

Here’s the relevant reference on code size limitations: http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#6254

Cheers,
Brian.