Why i get this error while compiling the Java file in J2ME. Is it because extensive use of array Objects since i have a lots of array Objects defined in the Java file 开发者_运维技巧?
It might be an array initializer within a method, as in:
void someMethod() {
int[] array = {0, 1, 2, 3};
}
This is equivalent to:
int[] array = new int[4];
array[0] = 0;
array[1] = 1;
array[2] = 2;
array[3] = 3;
and each element assignment takes four VM instructions (between 4 and 12 bytes of code per element.)
If the initializer is too long, it will exceed the 32K limit on the length of a method.
There is restriction with 32KB with method code, note that not with class file size.
Simple code
public void foo() {
int arr[] = {1, 2, 3};
}
will turn into [used javap to obtain this result]
public void foo();
Code:
0: iconst_3
1: newarray int
3: dup
4: iconst_0
5: iconst_1
6: iastore
7: dup
8: iconst_1
9: iconst_2
10: iastore
11: dup
12: iconst_2
13: iconst_3
14: iastore
15: astore_1
16: return
So you can imagine your huge & ocmplex array would turn into what size.
I suggest that you move your data into external resources in .jar file, it will also compress much better. also try optimizing it
精彩评论