我曾经在Java类中写过这一行。这在Eclipse中编译得很好,但在命令行上却没有。
这是
任何线索?
命令行上给出的错误是:
Icons.java:16: code too large
public static final byte[] compileIcon = { 71, 73, 70, 56, 57, 97, 50,
^
有问题的代码行是:
public static final byte[] compileIcon = { 71, 73, 70, 56, 57, 97, 50,
0, 50, 0, -9, 0, 0, -1, -1, -1, -24, -72, -72, -24, -64, -64,
-8, -16, -24, -8, -24, -24, -16, -24, -32, -1, -8, -8, 48, 72,
-72, -24, -80, -80, 72, 96, -40, -24, -24, -8, 56, 88, -56,
-24, -40, -48, -24, -48, -64, 56, 80, -64, 64, 88, -48, -56,
-64, -64, -16, -24, -24, -32, -40, -40, -32, -88, -96, -72,
-72, -72, -48, -56, -56, -24, -32, -32, -8, -8, -1, -24, -40,
-56, -64, -72, -72, -16, -32, -40, 48, 80, -72, -40, -96, -104,
-40, -96, -96, -56, -104, -104, 120, 88, -104, -40, -64, -80,
-32, -88, -88, -32, -56, -72, -72, -80, -80, -32, -80, -88,
104, -96, -1, -40, -40, -40, -64, -104, -104, -32, -56, -64,
-112, 104, 112, -48, -104, -112, -128, -112, -24, -72, -80,
-88, -8, -8, -8, -64, -112, -120, 72, 104, -40, 120, 96, -96,
-112, -96, -24, -112, -120, -72, -40, -88, -88, -48, -64, -72,
-32, -72, -80, -48, -72, -88, -88, -72, -24, 64, 88, -56, -120,
96, 104, 88, -128, -72, 48, 56, 56, 104, 104, 120, 112, -120,
-16, -128, 104, -88, -40, -48, -48, 88, -120, -24, 104, 88,
-104, -40, -56, -72, -128, 112, -88, -128, 96, -88, -104, -88,
-24, -96, -120, 120, -88, -128, -80, -56, -56, -64, 96, 120,
-8, -96, -128, -88, -80, -96, -104, -32, -72, -72, 96, 104,
112, 96, -104, -8, -72, -112, -112, -64, -72, -80, 64, 64, 72,
-128, -120, -96, -128, 88, 88, -56, -72, -80, 88, 96, 120, -72,
-128, 112, 72, 112, -40, 96, 120, -56, 88, -112, -16, 64, 104,
-48, -64, -80, -88, -88, -120, -80, 88, 88, 96, -56, -96, -120,
-40, -56, -64, 96, 104, 120, -120, -80, -24, -104, -88, -40,
-48, -72, -80, -64, -56, -16, -88, -112, -128, -32, -48, -56,
-24, -16, -8, -64, -120, 120, -96, -96, -88, 80, -128, -24,
-56, -72, -88, -96, 120, 88, -72, -112, 120, -64, -104, 120,
-48, -56, -64, -120, -104, -32, -104, 120, -80, -96, -112,
-120, 56, 88, -64, -128, 96, 64, 88, 120, -40, -80, -104, -120,
-104, -128, 104, 96, -104, -24, -72, -120, -128, 56, 96, -56,
-128, 112, 104, -48, -88, -112, 96, 96, 104, -104, -88, -72,
-40, -88, -96, -72, -88, -96, -120, 120, 104, -80, -88, -96,
72, 72, 80, -120, 88, 96, 120, -120, -24, 96, -104, -16, 104,
80, 48, -56, -80, -96, -56, -88, -104, -104, 120, -88, -88,
120, 104, -72, -120, -120, -24, -32, -40, 112, 88, -104, 120,
96, -104, -32, -32, -32, -96, 96, 96, 80, 80, 88, 64, 88, 120,
72, 120, -40, 72, 88, 112, -88, -96, -104, -56, -80, -88, -72,
-88, -104, -56, -64, -72, -80, -120, 104, -80, -120, -80, -112,
112, -88, 120, 112, 112, 112, -96, -24, -120, -120, -64, -120,
120, -80, 64, 96, -128, 96, 64, 64, 96, -128, -32, 80, 112,
-24, 112, -120, -24, 104, -96, -8, 96, 120, -16, -88, 120, 120,
-72, -56, -16, -128, -128, -128, -104, -120, -72, -64, -96,
-120, -32, -64, -64, -40, -48, -56, -64, -88, -96, -64, -104,
-72, -96, -88, -24, -104, -96, -40, -96, -128, 96, -128, -128,
-96, 104, 88, 80, 112, -88, -8, -64, -104, -80, -96, -120, 112,
96, 120, -32, 56, 80, -72, -104, -88, -32, 104, -128, -24, -56,
-88, -120, -80, -72, -8, -96, -128, -128, -64, -128, 96, -72,
-96, -120, 72, 104, -32, -96, 96, 64, -72, -96, -112, -32, -40,
-48, -64, -88, -112, -88, -128, 96, -88, -128, -88, -64, -64,
-32, -128, -96, -32, -88, -104, -112, 32, 32, 64, -120, 104,
-88, 120, -120, -16, -104, 120, -72, -24, -48, -56, -96, -96,
-96, -64, 96, 96, 96, 64, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, 0,
50, 0, 50, 0, 0, 8, -1, 0, 1, 8, 28, 72, -80, -96, -63, -125,
8, 19, 42, 92, -120, 112, 0, 3, 6, 12, 23, 6, -104, 72, -79,
-94, -59, -117, 19, 39, -124, 64, -128, -128, 3, -121, 9, 19,
48, -118, -92, 24, 81, 33, -118, 8, 40, 7, -88, 84, -55, -64,
12, 6, 6, 45, 74, -54, 52, 8, 73, -60, 24, 22, 25, 92, 73, 40,
64, -96, -64, 74, -121, 24, 94, -58, -100, 25, -79, -59, 47,
17, 3, 52, -120, 88, -125, 105, 73, 6, 42, -102, -68, 96, -16,
-71, 18, 3, -118, 6, 13, 14, -114, -36, 26, -64, 69, 7, 18, 28,
-61, -110, -32, -32, -62, -54, -94, 72, -61, -48, -88, -40, 72,
34, -60, 4, 21, 23, -119, 14, -92, 80, -58, 6, -108, 10, 18,
44, 68, -8, 57, -96, -128, 16, 98, 70, -24, -48, 97, -45, 6, 4,
6, 16, 67, -27, 18, 52, -79, -52, -89, -46, 49, -105, -74, -32,
109, -45, -85, -63, -49, 2, 13, 88, -51, -62, 5, 40, 80, 31,
91, 103, 20, 11, -116, 32, -124, -81, -54, 2, 40, -58, -40,
-103, -59, -122, 13, 43, 51, 12, 122, 106, 96, -48, 0, -105,
40, 29, 106, 32, 17, 20, -64, -69, -73, -17, -33, -68, 25, 113,
13, 80, -125, 44, -102, 72, 108, -84, -88, 80, 49, -127, -61,
-94, 28, -97, -108, -4, -98, -103, 102, 9, -127, -21, -40, -81,
23, -32, 35, -126, 39, -10, 2, 32, -116, 29, -1, 27, -74, 37,
-40, 29, 60, 90, -60, -120, -90, 0, -122, -118, -23, -107, 54,
-36, -72, -15, 2, 66, -61, -23, -39, 24, -8, -36, -7, -108,
-27, -128, 44, -59, -112, -16, -64, 67, 3, -39, 21, 72, 0, 6,
34, 120, -31, -123, 124, 124, 52, 16, 84, 3, -119, -88, 82,
-62, 28, -2, 21, 4, -36, -123, -83, -92, -96, 97, 13, 20, 117,
112, 2, -121, 24, 77, -128, 6, 48, -64, 72, -93, -62, 31, 104,
-56, 48, 68, 16, 65, 112, 49, 29, 67, 82, 8, 24, 72, 118, 18,
84, 48, 66, 6, 63, 72, 96, 96, 1, 26, -128, 64, -97, 8, 50, 24,
114, -64, -112, -22, -51, -28, 7, 24, 77, 116, -15, 75, 1, 123,
53, 2, -63, 15, 22, 88, 0, 1, 5, 44, 72, 32, -127, 74, -78,
-47, -122, -62, 27, -90, -24, 49, -28, 1, 69, -106, -108, 76,
21, -99, 8, -127, -119, 29, -81, 60, 41, -63, 15, 16, -116, 80,
65, -114, 22, -44, 40, 72, 6, 111, 60, 4, 77, 3, 34, -124, 1,
-60, -105, 7, 40, 96, -31, -123, -68, 49, -111, 66, 30, 32,
102, -92, 66, 30, 86, 60, -47, -63, 12, 30, 42, 58, 67, 13, 51,
120, -32, 1, 35, 30, 112, 112, -62, 39, -114, -80, 24, -124,
116, 47, 30, 116, 6, 15, -120, 24, -104, 93, 3, -105, 44, -79,
12, 11, -103, -116, 112, 35, 20, 52, -96, 64, 3, 32, 91, -40,
-1, 114, 5, -97, 126, -106, 36, 5, 24, -106, -67, 103, 26, 3,
32, -68, -14, 10, 20, 44, 88, -78, -124, 37, 91, -124, -47,
-33, -105, 112, -56, -28, 7, -103, -70, -86, 116, -57, 29, 52,
80, 37, -101, 8, 54, 24, 99, -121, 17, 82, -108, -80, 0, -83,
7, 93, 56, 70, 14, 41, -96, -78, -107, 11, -117, -48, 97, -42,
12, 127, 32, 64, 66, 91, 19, -96, -88, -94, 35, -16, 110, 10,
-88, 65, 103, 76, -62, 67, 19, 114, -120, -102, 93, 49, 107,
-108, 65, -121, 29, -121, -36, 65, -116, 16, 24, -32, 121,
-125, 33, -70, 108, -96, 112, -97, 37, 5, -127, 100, 23, -128,
-4, 68, 65, 5, 123, -103, 102, -63, 24, 101, -20, 49, -51, 33,
-121, -40, 80, 65, 9, 122, 40, -84, 112, -78, 17, 73, 81, 69,
-110, -110, -28, -38, -105, 9, 84, -30, 69, 21, -106, 60, 106,
32, 68, 25, -127, -96, -96, -25, 6, 14, 56, -96, 112, -83, 90,
81, 116, 2, -72, 57, 16, 66, 8, 88, 28, 49, 26, 66, 8, 51, 60,
-15, -60, 9, 51, -128, -75, -82, 91, 19, 116, 96, -87, 12, 31,
84, 93, -75, 18, 91, 13, 100, -126, -67, 125, 72, 50, 72, 45,
63, 89, -112, 1, 5, 20, -104, 96, 65, 1, 38, -4, 48, 49, 4,
-82, 60, 84, 48, 13, -90, 92, -111, -13, -36, 60, 39, -44, 66,
40, 96, -12, -47, -59, 32, 81, -20, -1, -15, 19, 4, 18, 68, 80,
64, 5, 72, -80, 0, -127, 9, 17, 72, -112, 9, 20, -106, -48,
-48, -86, -79, 56, -49, 77, -14, 66, -76, -100, -68, 119, 20,
59, 44, -15, 19, -53, 20, 0, 30, 103, -101, 110, -66, 97, -122,
25, 52, 44, 33, -125, -74, 11, -92, -98, 115, -35, 90, -55, 1,
52, 33, 83, 76, 33, -118, 10, 97, 73, -70, 81, 7, 29, 44, -35,
1, -46, 29, 76, -22, 2, 7, 30, -84, 50, -60, 7, 48, 60, 114,
-11, 112, 0, -124, -95, 67, 21, -110, 96, -66, -61, 14, 12,
-84, 36, -27, 8, -99, -101, 80, -128, 5, 72, -36, -104, -55,
23, -92, 83, -95, -116, 19, 14, -92, 46, 62, -21, 8, 21, 1, 68,
9, -93, -124, -78, 3, 51, 59, -68, -84, 82, -30, 72, 84, 64, 1,
18, 121, 85, 0, -123, 32, -126, -80, -112, 6, -56, 11, -32, 32,
-2, -28, 10, -71, -64, 5, -80, 48, 7, 74, 56, -63, 16, 58, -40,
65, 45, -28, -16, 5, -108, 56, 16, 37, -112, -80, 17, 5, 70,
-16, 6, 87, 124, -127, 5, -98, 0, -126, 3, 30, -128, -125, 14,
-30, 64, 1, 2, 12, -95, 8, 67, 8, 0, -118, 108, -126, 8, 31,
-16, 1, 40, 100, -96, -120, 20, 76, 33, 18, 121, -104, 64, 88,
102, 24, 2, -78, 48, 66, 5, -101, -96, 26, 12, 118, -72, 67,
100, 12, 103, 34, 4, 89, 65, 18, -1, 72, -127, -125, 2, 30, 80,
7, -107, -24, -37, 22, 26, -15, -66, 2, 20, -96, 17, 12, 64,
65, 52, -30, -74, -128, 7, 88, -47, -118, -28, 99, -120, 2,
122, -112, -124, 36, -100, 34, 1, 14, -48, -126, 26, 74, -128,
-121, 80, 68, 33, 10, -127, -80, -127, 6, 98, -122, 1, 42, 120,
34, 11, 27, -72, -94, 21, 1, 56, 19, 50, 116, -47, -117, -89,
32, -59, 3, 28, 112, 5, 39, -108, 0, -119, 81, 16, -123, 17,
108, 96, 6, 42, -8, 65, 91, 15, 72, -128, 28, -77, -120, 16,
-116, -64, -30, 25, 113, -120, 100, 36, -101, -15, 8, 24, -84,
80, 6, 46, -116, 93, 36, -124, -9, 1, 34, 120, -46, -109, 71,
-8, 33, 73, 16, 66, -122, 21, -12, -32, -108, 61, 40, 5, 47,
18, 48, -121, 62, -2, 113, 18, 58, 112, -62, 6, 18, 64, -53,
90, 50, 82, 49, 10, 40, -62, 41, 11, -63, 75, 94, -68, 32, 117,
106, -16, -93, 30, 18, 89, -53, 4, -60, 64, 52, 10, 81, -128,
47, 86, -64, 76, 102, -106, 34, 23, 47, -48, -126, 22, 28, 80,
76, 90, -34, 82, 32, 6, -56, -90, 54, 69, 25, 0, 38, -64, -126,
11, 71, 8, -89, 56, -107, -96, 8, 31, -104, -45, 7, 68, -32, 2,
55, -127, 72, -108, 11, -112, -95, 8, 49, -120, -89, 60, 71,
-15, -126, 122, 38, -32, -102, -56, 60, -120, 2, 110, 80, 51,
-124, 126, -58, -94, 8, -62, -88, -25, 49, -13, 41, 23, 5,
-112, -31, 6, 8, 93, 65, 64, -15, -39, -56, 117, 98, -124, 9,
51, -72, -59, 45, 56, -95, 78, -121, 6, -128, -96, 5, -39, 39,
67, 49, -54, -47, -114, 122, -44, 32, 1, 1, 0, 59 };
答案 0 :(得分:4)
从this forum on Sun's support site开始,没有任何方法可以超过64 KB:
如果您拥有以下代码(伪)......
class MyClass
{
private String[] s = { "a", "b", "c"}
public MyClass()
{
}
编译器最终生成的代码基本上如下所示。
class MyClass
{
private String[] s;
private void FunnyName$Method()
{
s[0] = "a";
s[1] = "b";
s[2] = "c";
}
public MyClass()
{
FunnyName$Method();
}
如上所述,java将所有方法限制为64k,甚至是编译器创建的方法。
Eclipse可能会偷偷摸摸地解决这个问题,但我向你保证,在Eclipse中这仍然是可能的,因为我看到了同样的错误信息。更好的解决方案是从静态文件中读取,如下所示:
public class Icons
{
public static final byte[] compileIcon;
static
{
compileIcon = readFileToBytes("compileIcon.gif");
}
//... (I assume there are several other icons)
private static byte[] readFileToBytes(String filename)
{
try {
File file = new File(filename);
byte[] bytes = new byte[(int)file.length()];
FileInputStream fin = new FileInputStream(file);
fin.read(bytes);
fin.close();
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
答案 1 :(得分:3)
你似乎有什么编译。
如果可能的话,我建议尝试将资源嵌入Jar并使用 ClassLoader.getResourceAsStream()。
答案 2 :(得分:3)
Eclipse拥有自己的编译器。 Eclipse JDT编译器似乎以不同于javac的方式处理您的数组。
答案 3 :(得分:2)
很难说出为什么会出现命令行编译错误,但是......
由于你有很多“魔术数字”,所以可能有一种比硬编码数组文字更好的方法。
考虑
答案 4 :(得分:1)
提供准确的错误信息也有助于我们帮助您...
我想知道为什么你在源代码中硬编码图像(图标),而不是使用某种形式的资源。
答案 5 :(得分:0)
很难说从提供的内容,但猜测是
什么是编译错误?
你可以在虚拟课堂中隔离问题进行演示吗?
答案 6 :(得分:0)
如果你在Windows上 写
设置JAVA_HOME = C:\ Program Files .... JDK的路径 路径应该是jdk路径而不是jre 在我的电脑上是C:\ Program Files \ Java \ jdk1.6.0_07
警告:路径不应该被引号所围绕(“)cmd的自动填充会让它们发生!
在类似unix的系统上使用
导出JAVA_HOME = 路径到JDK (可以容忍引号)
答案 7 :(得分:0)
您确定您的命令行和eclipse使用相同版本的Java编译器和相同的编译设置吗?要在命令行类型中找到您正在使用的Java版本:Java -version