0

I got it working. I cut so much of it into even smaller methods, and now it seems to be working. Gah I'm so stupid >.<

(Prior issue I had one HUGE line of code without any methods. Works not that it's into smaller methods)

NewGuyChris
  • 29
  • 1
  • 6

1 Answers1

0

It's a limitation in Java. In short, your onCreate() is too big. Break it up into smaller methods, do work in onStart() and onPause, execute AsyncTasks to avoid doing all of the loading on the main thread.

It's generally good practice to keep your methods small and simple, so if you run into this problem

See Why does Java limit the size of a method to 65535 byte? for reference.

Just out of curiosity, how many lines of code does your onCreate() contain?

Community
  • 1
  • 1
Qw4z1
  • 3,041
  • 1
  • 24
  • 36
  • It's embarrassing, but over 2,100 lines. I've tried to separate them into methods. I just named them test1 and test2 for the time being. I then run the methods from onCreate. The first test1 method works, but the second doesn't. method test1 has 741 lines of code that sets the images based on the Spinner Text. Method test2 has even more lines of code to set the warning TextView. When, when the conditions are met in test2 to make the warning appear, it doesn't appear. Yet it appears if I have it all in one method.... – NewGuyChris Nov 06 '13 at 04:18
  • @NewGuyChris That's a ridiculous, impossible-to-reason-about size for a method. Methods should be a dozen or two lines at the *most* in almost all situations. – Dave Newton Nov 06 '13 at 04:27
  • I'm sorry. I know. I have now separated them into methods and have the methods running after onCreate(). However, only one method runs fine and the other doesn't. Guess I need to tinker around more. Thanks anyways for the help. It's much appreciated! – NewGuyChris Nov 06 '13 at 04:31
  • I got it working. I cut so much of it into even smaller methods, and now it seems to be working. Gah I'm so stupid >. – NewGuyChris Nov 06 '13 at 04:35
  • @NewGuyChris You're a beginner, not stupid. There is a big difference there. =) 2,100 lines is a bit ridiculous, though. I generally try to keep my (java) methods below 20 lines. Just read up on programming best practices and you will be fine. – Qw4z1 Nov 06 '13 at 06:22
  • @NewGuyChris Actually, even 10 lines is much. One method should ideally do one thing and one thing only. And don't be afraid to break up your classes into smaller classes. 741 lines is generally too much for a single class even. – Qw4z1 Nov 06 '13 at 07:32