| Author |
code too long
|
sanjeev mehra
Ranch Hand
Joined: Feb 12, 2001
Posts: 93
|
|
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.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
I am surprised that there is limit for writing code in java file.
There isn't. Show us your code (or a truncated version if it is very long).
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
sanjeev mehra
Ranch Hand
Joined: Feb 12, 2001
Posts: 93
|
|
able to compile this file. 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 ]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
|
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
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
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
|
|
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 ]
|
 |
sanjeev mehra
Ranch Hand
Joined: Feb 12, 2001
Posts: 93
|
|
Thanks to all of you for quick reply & suggestions. Regards, Sanjeev.
|
 |
 |
|
|
subject: code too long
|
|
|