This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes code too large Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "code too large" Watch "code too large" New topic
Author

code too large

eric guo
Greenhorn

Joined: Apr 17, 2007
Posts: 2
Hi,

I have a UI class regenerated by NetBean 5.5. the "regenerated" means I cannot simply refactor the code. Basically, the problem is one method called initComponents() has 6000 lines. so the compiler shows a "code too large" error, which is because of the 64K size limit of one method in JVM, I believe.
My question is if there is a way to compile this code without defactoring it.

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Welcome to the Ranch.

If you really have a method which exceeds 64K then you will probably have to reprogram it rather than only refactoring.
Scott Escue
Ranch Hand

Joined: Jan 20, 2005
Posts: 34
Eric,

For Netbeans to generate a method that large you must have a ton of components added directly to a container. You could, and arguably should, refactor this by creating mid-level containers so that your top-level container doesn't have so many components directly attached. This would reduce the amount of code in your existing initComponents method and should alleviate your problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
I didn't notice it was initComponents() which was so large. This is the automatically-generated method using the GUI builder in NetBeans. As Scott Escue says, you will have to divide that into smaller methods. You must have a very large display to get 6000 lines!
eric guo
Greenhorn

Joined: Apr 17, 2007
Posts: 2
Hi Campbell,

Thank you for your reply. I've tried to refactor the initComponents to smaller size sub-methods. and it works fine. however, the root cause of this problem may like what Scott said, and yes, there are tons of components added in one container. it is not easy to rewrite the whole thing.

Thank you all again for your help.

Eric
Scott Escue
Ranch Hand

Joined: Jan 20, 2005
Posts: 34
Eric,

You should be able to refactor this in the GUI builder without too much trouble. Just add several JPanels to whatever container is giving you trouble and move some of your components onto the sub-panels. There shouldn't be any need to modify the initComponents method by hand.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Good idea, Scott.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: code too large
 
Similar Threads
Please help me solve this problem
interesting question.. !!
To invoke more JPanels separately (one by one) on the same position of the JAplet
[Event handling] Implementing ActionListener vs. anonymous inner function
java code too large