Limitation of the number of lines in a sub?

Pantelis

Member
Licensed User
Longtime User
I am trying to write a sub with many lines of code but when i complile, b4a gives me this error message if my code lines are more than 2959 in this sub.

Compiling generated Java Code. Error
Javac 1,0,0_13
src\b4a\example\main.java:325: error: code too large for try statement
try {
^
1 error

when I change the compilation method from Debug to Release it allows more lines of code in one sub but gives me the following similar error message after line 10922.

Compiling generated Java Code. Error
Javac 1,0.0_13
src\b4a\example\main.java:33155:error: code too large for try statement
catch (Exeption e) {
^
1 error
 

Pantelis

Member
Licensed User
Longtime User
In these line codes i set lots of values. So i will breake my code to smaller subs.

So, there is a limit of the lines of code in one sub. What is that limit? Are there any other limitations? The number of subs in an activity, or the total number of lines in an activity or in a process?
Is there a place where I could find those limits of Java?

Thanks Erel.
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
If you write each variable to a line, then you should try setting multiple variables in each line. This can be easily done by using excel or something like this. Still, you can create subs and call them from inside your try-catch block, no matter how big the arrays are. Furthermore, why not getting the data from a file? You can even use encryption if you worry for data's safety.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As mc73 already suggested: Furthermore, why not getting the data from a file? This should be your solution ! You could write a small program to generate these files.
I remember having read somewhere that a Sub should not exead something about 20 lines to keep an overlook.
And I agree with this !

Best regards.
 
Upvote 0

Pantelis

Member
Licensed User
Longtime User
If you write each variable to a line, then you should try setting multiple variables in each line. This can be easily done by using excel or something like this. Still, you can create subs and call them from inside your try-catch block, no matter how big the arrays are. Furthermore, why not getting the data from a file? You can even use encryption if you worry for data's safety.
Thanks for suggestions mc73


You could write a small program to generate these files.
Thank you Klaus. I like this idea.

I remember having read somewhere that a Sub should not exead something about 20 lines to keep an overlook.
And I agree with this !
20 lines?! Interesting.

This is a limit of the JVM. The limit is 64kb (JVM bytecode) for a single sub. Again there is no reason to have such a huge sub.

There aren't any other limitations.
Thank you very much Erel for information.

WOW! A 10,000+ line sub? That gives me a headache just thinking about it. :BangHead:
:)
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
Who remembers the old 'DATA' command In ancient BASIC ? :)

I do - in fact I have converted several old Basic programs (written in GWBasic) to B4A and dealing with the old DATA and READ statements was sometimes a real challenge as is creating an alternative to GoTo (Case statements work well for this).
 
Upvote 0

shaxboz

Member
Licensed User
Longtime User
Hi!
my b4a has line limits for code editor. Why I cannot write more than 2225 lines in one activity code?
 

Attachments

  • b4aError.jpg
    b4aError.jpg
    486.3 KB · Views: 279
Upvote 0
Top