This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am getting data from excel sheet & creating a two dim object array. I am able to generate java code successfully file based on that data excel But while compilation of that file, I am getting code too long error. I am able to create two dim object array of 2425 rows but more than that is not working. I am surprised that there is limit for writing code in java file. I will appreciate your comments. Thanks.
if I add more records in excel file, I am able to generate java file properly but when I compile it, it gives me error. [ October 04, 2005: Message edited by: sanjeev mehra ]
There is indeed a limit to the amount of bytecode in a method. Initializing a long array can exceed that limit. Instead of hardcoding the data, write it into a file, and have the class read it in at runtime.
Yikes, I'd guess you've run into a system or compiler limit that's not necessarily part of the language spec.
Can you change your code generator to write all the data to a file and read the file in your Java program? Then your code could be very short:
You could probably even open the spreadsheet as a database with JDBC/ODBC or one of the Java COM bridges like JACOB or a special office IO project like POI.
Any of those choices sound appealing?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James: Yikes, I'd guess you've run into a system or compiler limit that's not necessarily part of the language spec.
It's not explicitly part of the language, but it's implicitly included because it's part of the VM spec. The size of a method's bytecode is kept in a UINT16, so 65535 bytes is the maximum. Not everyone realizes this, but when you write
int[] x = { 1, 2, 3 };
The compiler emits code that looks like
int[] x = new int[3]; x[0] = 1; x[1] = 2; x[2] = 3;
and each of those assignments can take quite a few bytes to encode, as the values have to be fetched from the constant pool and put on the stack, the array reference put on the stack, and then the assignment bytecode invoked. [ October 04, 2005: Message edited by: Ernest Friedman-Hill ]