I have the following code:
public static void main(String[] args) { try { String[] studentnames = { /* this is an array of 9000 strings... */ }; } }
I get the following error when trying to compile this:
The code of method main(String[]) is exceeding the 65535 bytes limit
If a subjob is too big, the size of the final generated code will exceed 65536 bytes. According to Java specifications, the amount of code for this non-native, non-abstract method is limited to a size of 65536 bytes, so the generated code of a subjob cannot be greater than this limit.
A text column can be up to 65,535 bytes. An utf-8 character can be up to 3 bytes. So... your actual limit can be 21,844 characters.
In java a methods can't have more than 65535 bytes.
So to fix this problem, break up your main(String[] args)
method in to multiple sub methods.
The error code seems quite self-explanatory.
The code of method main(String[]) is exceeding the 65535 bytes limit
This is because there is an arbitrary hard-coded limit in Java of 64Kb for method sizes. (And actually many other things are limited to 64K, such as method names, the number of constants, etc. See the Java 8 specs or the Java 7 specs for more details.)
To work around this, all you have to do is break up your main(String[] args)
method into multiple sub-methods.
But why not just load the names from a file instead?
Some of the issues with doing it the way you are currently proposing are:
firstly, you're hard-coding details, which is almost always a bad thing (See this);
secondly, you're getting that error message; and
thirdly, you make your code very difficult to read.
There are many more, of course, but these are the obvious ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With