Android Question Select Case compiles ok but run no good

Discussion in 'Android Questions' started by Scantech, May 16, 2019.

  1. Scantech

    Scantech Well-Known Member Licensed User

    I know the Select Case statement is large. When i run the class it leads to this error. But when i compile, it is ok. Should I be concerned with this? Will it pose a problem if i don't split it? It did compile ok.

  2. Cableguy

    Cableguy Expert Licensed User

    I remember reading somewhere that nested IFs and long/complex Select Case could have some limitations… I'll try to find where I read it
  3. Scantech

    Scantech Well-Known Member Licensed User

    I think it is safe. Because i ran the project in debug it failed. Ran it in Release mode it did run without any errors. Safe to say its good in compilation mode.
  4. emexes

    emexes Well-Known Member Licensed User

    It looks like an error from the Java compiler, eg: which states:

    This error is due to a limit on the number of source lines the Java compiler allows in a single block.

    (I later found a better discussion of the issue at:

    and so I guess:

    in release mode, your nnn lines of BASIC code is translated/compiled by B4A to ooo lines of Java that is less than the abovementioned limit,
    and thus the Java compiler is ok with,


    in debug mode, B4A is adding extra debug-related lines of Java code that results in ppp lines of Java that is over the abovementioned limit, and thus the Java compiler emits the "code too large" error to B4A which then handballs back to you.

    Me personally, if I got that message, I'd be keen to get rid of it, and would try to restructure my code to resolve the situation.

    Like, if it is a Select Case inside the Catch part of a Try statement, then I'd try moving that error-handling code into a separate Sub.

    p.s. Minor observation, not sure if it matters, but: the error says a Try statement (Catch block?) is too large, not a Select Case statement

    error: code too large for try statement catch
    Last edited: May 17, 2019
    Shelby and Scantech like this.
  5. emexes

    emexes Well-Known Member Licensed User

    Any chance of posting a sample of the code that causes the "code too large" error? I'm intrigued by what block of code would generate more than 64k of compiled byte code... that sounds like a lot of typing.

    No worries if you'd rather not, eg prefer keep commercial code private.
    Shelby likes this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    There are no limitations. In the early days of B4A Select Case blocks could not be nested, this is no longer the case.

    In most cases where you see such errors it means that you are doing something wrong. Usually it happens when you combine the program data inside the code. This is a common mistake. One solution is to split the sub. A better solution is to move the data to a file.
    Cableguy and Scantech like this.
  7. Scantech

    Scantech Well-Known Member Licensed User

    I wish i thought of it 8 years ago. I like the idea moving data to file but its way too many codes. I rather split the sub for now.

    One question. When i compiled it and used the library with another project running in debug mode did not cause any errors?
  8. emexes

    emexes Well-Known Member Licensed User

    I am guessing it is because the library code was compiled in release mode, without the extra Java code lines added for debugging.

    This link says that the limit is 65535 bytes of compiled byte code, which makes me think that it is something to do with byte code jump destinations being 16 bits.

    65k of compiled code is a pretty big Sub, eg, if an average B4A line compiled to 15 bytes, then that's 4000 lines = 60 pages of code, which seems like a pretty generous limit for one Sub or block or whatever the limit applies to.
    Scantech and Shelby like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice