Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Code too large" compilation error in Java

Is there any maximum size for code in Java? I wrote a function with more than 10,000 lines. Actually, each line assigns a value to an array variable.

arts_bag[10792]="newyorkartworld"; arts_bag[10793]="leningradschool"; arts_bag[10794]="mailart"; arts_bag[10795]="artspan"; arts_bag[10796]="watercolor"; arts_bag[10797]="sculptures"; arts_bag[10798]="stonesculpture";  

And while compiling, I get this error: code too large

How do I overcome this?

like image 845
trinity Avatar asked Mar 09 '10 09:03

trinity


People also ask

How do you fix a compilation error in Java?

Mismatched brackets If the brackets don't all match up, the result is a compile time error. The fix to this compile error is to add a leading round bracket after the println to make the error go away: int x = 10; System.

What is a Java compilation error?

Compile-time errors occur when there are syntactical issues present in application code, for example, missing semicolons or parentheses, misspelled keywords or usage of undeclared variables. These syntax errors are detected by the Java compiler at compile-time and an error message is displayed on the screen.


1 Answers

A single method in a Java class may be at most 64KB of bytecode.

But you should clean this up!

Use .properties file to store this data, and load it via java.util.Properties

You can do this by placing the .properties file on your classpath, and use:

Properties properties = new Properties(); InputStream inputStream = getClass().getResourceAsStream("yourfile.properties"); properties.load(inputStream); 
like image 188
Bozho Avatar answered Sep 30 '22 07:09

Bozho