aspose file tools*
The moose likes Java in General and the fly likes code too large Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
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: 39393
    
  28
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: 39393
    
  28
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: 39393
    
  28
Good idea, Scott.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code too large