6

I have a project I have been working on and all was going well until today. I have close to 6000 lines of code in one java class document. If I try to put one more IF clause into the code, the program throws an exception when the class is called on. All additional snippets that I have tried to place into the class, cause the class to fail when called on. I have tried to add test code that I know works fine, and they all throw the force close alert dialog. Trust me there is nothing wrong with the last snippet that I attempt to place into the class. Once I take out the last "if" snippet, there are no errors. Has anyone ever seen this before? The exception is thrown in the emulator, when the class is called. I get the force close alert window. Here is the java file size: 172,503 bytes Thanks in advance!

lastshadowrider
  • 103
  • 1
  • 9
  • 1
    *"...the program throws an exception when the class is called on"*. What exception? Where is the exception thrown? By Eclipse? In the running program? What do you mean by "called on"? – Stephen C Apr 21 '12 at 04:04
  • 2
    You may be running into the 64kb (of bytecode) method size limit. http://stackoverflow.com/questions/107855/is-there-any-no-of-lines-code-limit-for-a-java-class and http://stackoverflow.com/questions/5689798/why-does-java-limit-the-size-of-a-method-to-65535-byte and http://stackoverflow.com/questions/6570343/maximum-size-of-a-method-in-java – Matt Ball Apr 21 '12 at 04:06
  • 7
    I should point out that a class with 6,000 lines of code is indicative of a **REALLY** bad design. If you refactor / modularize your code to something more reasonable, the problem should go away. – Stephen C Apr 21 '12 at 04:06
  • Thanks I thought I was barking up the wrong tree, with over 6000 lines of code in one class. I just needed someone to say it. Will look at restructuring. I probably have 2000 more lines to go in this class, but dont see any other way to do it, being a nub. – lastshadowrider Apr 21 '12 at 04:12
  • 2
    *"I probably have 2000 more line to go in this class, but dont see any other way to do it, being a nub."*. Clearly, you **have to** rethink your design. If you can't figure it out for yourself, find yourself a Java mentor. (Or maybe post the code on the "codereview" sister site asking for advice on how to refactor it. Though 6,000 lines of code is unlikely to be welcome ... anywhere.) – Stephen C Apr 21 '12 at 04:16
  • Thanks Stephen C I'm going with the quick fix of chopping up the class into smaller chunks, and I will restructure the project in subsequent builds. The links you posted, really helped !!! – lastshadowrider Apr 21 '12 at 05:02

4 Answers4

4

you can modify the same using following settings:

--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
Satya
  • 8,693
  • 5
  • 34
  • 55
3

I ran into that problem some time ago and found out that its no problem to have 50k lines and more of code in one class as long as the method limit is not exceeded.

Depending on what's in one single method that actually causes the bytecode size I experienced limitations between 2-3k lines of code/method.

added:

by the way at a certain point in fact Eclipse crashes when your total code becomes too large to compile - just increase Eclipse's memory to 1 Gb or so. SO far that was enough for my projects having around 100k lines in total...

user387184
  • 10,953
  • 12
  • 77
  • 147
  • I chopped the method up and redirected the other classes to find the chunks, it works like a charm. The method size was exceeded. This one cost me a whole day. But what is a day in the life of a nub worth anyway LOL – lastshadowrider Apr 21 '12 at 08:08
  • @lastshadowrider Just curious, how many lines did your method have for it to crash? – blessanm86 Apr 21 '12 at 13:34
  • about 5,980 lines before it crashed. I thought I would just keep adding to the method, because everything was working fine. And then boom. – lastshadowrider Apr 22 '12 at 07:23
1

I've noticed this before, Eclipse runs off of Java itself, so it is very RAM intensive, if you have too much code so that it needs more than can be alloted it will crash.

Jeremy Sayers
  • 637
  • 4
  • 10
  • 23
1

Is there a limit on the number of lines of code you can put in an Eclipse java doument.

Not precisely.

There are limits on the number of bytecodes in a compiled method, and other things like that, but these are imposed by the Java classfile format (i.e. the JVM specification) not by Eclipse.

It is also possible that Eclipse needs more memory, though I don't think that adding a single if statement would reliably trigger this. (And if it did, the exception would tell you that you were out of memory ...)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216