How to fix “The code of method .. is exceeding the 65535 bytes limit”?

后端 未结 8 946
执念已碎
执念已碎 2020-12-14 15:36

I have the following code:

public static void main(String[] args) {
    try {
        String[] studentnames = {
            /* this is an array of 9000 strin         


        
相关标签:
8条回答
  • 2020-12-14 16:12

    You method is too long.

    Create different methods to split it and make it much more readable and maintanable.

    0 讨论(0)
  • 2020-12-14 16:13

    The code of method main(String[]) is exceeding the 65535 bytes limit

    As your error says the main method exceeds the limit of 65535 bytes.

    Reason : Why we got this error in our code?

    • We know that the memory allocation for array would be done sequentially. ie; the memory would be allocated for the array if such a huge amount of space is available in RAM continuously.
    • We have used String array which holds some "9000" strings - which is too large to hold in the memory
    • The RAM might not have such a huge space continuously during that time so, we might have got that error.

    Solution : So what can I do for this?

    • For storing such huge size value we may prefer file for read/write - so we can read a part of a file when required
    • We can store those strings in an ArrayList which grows its memory when element gets added to it instead of allocating memory on a whole initially.
    0 讨论(0)
提交回复
热议问题