Java compile error: code too large

醉酒当歌 提交于 2020-01-05 09:33:29

问题


So we're working on an Enrollment System and now we're stuck because of memory error during compile.

We researched online and found that the reason is for the error message is the size of the .java file. Our EnrollmentSystem class now has 10171 lines of code.

We designed it using the GUI builder of Netbeans. We thought of creating a separate class to contain other panels but we don't know how to get the components from another class and add it to the original class(the one that contains 10171 lines) then show it's contents on the same tab.

*What we need to accomplish is that when user clicks on a specific tabbed pane, it shows the panels from another class.

I know it has something to do with object.add() instantiation

We tried getComponent(nth); but really don't know how to manage classes and add components from different classes.


回答1:


The simple answer to this is to (a) stop using your GUI editor and write your code by hand, and (b) split up the GUI init method into 2 or more sub-methods




回答2:


There is a 64K byte-code size limit on a method in Java due to the exception handling implementation:

The fact that end_pc is exclusive is a historical mistake in the design of the Java Virtual Machine: if the Java Virtual Machine code for a method is exactly 65535 bytes long and ends with an instruction that is 1 byte long, then that instruction cannot be protected by an exception handler. A compiler writer can work around this bug by limiting the maximum size of the generated Java Virtual Machine code for any method, instance initialization method, or static initializer (the size of any code array) to 65534 bytes.

This is true for Java 7 and 8.

You will have to split whatever method violates this constraint in two. There might or might not be a way to do this using the GUI Builder; you'll definitely have this option if you build your interface manually.



来源:https://stackoverflow.com/questions/34320675/java-compile-error-code-too-large

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!