Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code too large

 
eric guo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good idea, Scott.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic