• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

code too large

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76444
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76444
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76444
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good idea, Scott.
 
It will give me the powers of the gods. Not bad for a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic