2008-03-29
修复J2ME Game Script 的bug
原文在
今天在玩开源的Script的引擎的时候在解释下面script的时候出现问题,
你知道为什么吗
i = 5
j = 1232323
h = i + j
println(h)
抛出这个异常
4 : Illegal statment ,String index out of range: -9
java.lang.StringIndexOutOfBoundsException: String index out of range: -9
at java.lang.String.substring(Unknown Source)
at gscript.Interpreter.callSub(Interpreter.java:1355)
at gscript.Interpreter._sub(Interpreter.java:401)
at gscript.Interpreter.callSub(Interpreter.java:1353)
at gscript.Interpreter.start(Interpreter.java:227)
at gscript.Interpreter.start(Interpreter.java:198)
at ScriptTest.main(ScriptTest.java:12)
后来发现原来是println(h)少了一个换行符号。
现在我修改了下源代码。
我修改了下代码后,这个bug解决了
看原来的代码
for (int i = 0; i < srcBytes.length; i++) {
if (srcBytes[i] == 0x0a || i + 1 == srcBytes.length) { // 行结束,或者文件结束
try {
String s = new String(line.toByteArray()); // j2me使用
// String s = new String(line.toByteArray(), "GB2312");
// //j2se使用
s = s.trim();
srcCode[lineCount++] = s;
} catch (Exception ex1) {
}
line.reset();
} else {
line.write(srcBytes[i]);
}
}
修改后的代码
for (int i = 0; i < srcBytes.length; i++) {
if (srcBytes[i] == 0x0a ) { // 行结束,或者文件结束
try {
String s = new String(line.toByteArray()); // j2me使用
// String s = new String(line.toByteArray(), "GB2312");
// //j2se使用
s = s.trim();
//System.out.println(s);
srcCode[lineCount++] = s;
} catch (Exception ex1) {
}
line.reset();
} else {
line.write(srcBytes[i]);
if(i + 1 == srcBytes.length){
String s = new String(line.toByteArray()); // j2me使用
// String s = new String(line.toByteArray(), "GB2312");
// //j2se使用
s = s.trim();
s = s.trim();
//System.out.println(s);
srcCode[lineCount++] = s;
}
}
}
http://www.3geye.net/?3/viewspace-3196
今天在玩开源的Script的引擎的时候在解释下面script的时候出现问题,
你知道为什么吗
i = 5
j = 1232323
h = i + j
println(h)
抛出这个异常
4 : Illegal statment ,String index out of range: -9
java.lang.StringIndexOutOfBoundsException: String index out of range: -9
at java.lang.String.substring(Unknown Source)
at gscript.Interpreter.callSub(Interpreter.java:1355)
at gscript.Interpreter._sub(Interpreter.java:401)
at gscript.Interpreter.callSub(Interpreter.java:1353)
at gscript.Interpreter.start(Interpreter.java:227)
at gscript.Interpreter.start(Interpreter.java:198)
at ScriptTest.main(ScriptTest.java:12)
后来发现原来是println(h)少了一个换行符号。
现在我修改了下源代码。
我修改了下代码后,这个bug解决了
看原来的代码
for (int i = 0; i < srcBytes.length; i++) {
if (srcBytes[i] == 0x0a || i + 1 == srcBytes.length) { // 行结束,或者文件结束
try {
String s = new String(line.toByteArray()); // j2me使用
// String s = new String(line.toByteArray(), "GB2312");
// //j2se使用
s = s.trim();
srcCode[lineCount++] = s;
} catch (Exception ex1) {
}
line.reset();
} else {
line.write(srcBytes[i]);
}
}
修改后的代码
for (int i = 0; i < srcBytes.length; i++) {
if (srcBytes[i] == 0x0a ) { // 行结束,或者文件结束
try {
String s = new String(line.toByteArray()); // j2me使用
// String s = new String(line.toByteArray(), "GB2312");
// //j2se使用
s = s.trim();
//System.out.println(s);
srcCode[lineCount++] = s;
} catch (Exception ex1) {
}
line.reset();
} else {
line.write(srcBytes[i]);
if(i + 1 == srcBytes.length){
String s = new String(line.toByteArray()); // j2me使用
// String s = new String(line.toByteArray(), "GB2312");
// //j2se使用
s = s.trim();
s = s.trim();
//System.out.println(s);
srcCode[lineCount++] = s;
}
}
}
发表评论
- 浏览: 562629 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
我的相册
我女朋友
共 12 张
共 12 张
最新评论
-
Google产品大全
很全很全很全很全
-- by sheandwei -
说真的UCWEB看奥运真方便
楼下的。话不能这么说。我现在上班开奥运就靠它了,
-- by wuhua -
说真的UCWEB看奥运真方便
傻佬,这也值得说
-- by caohj -
UCWEB使用秘诀
最近发现UCWEB有准备发布新版本了。到时再仔细研究相关的一些特殊用法。
-- by wuhua -
开始进入另外一个领域
自己的水平还很菜啊。要努力学习
-- by wuhua






评论排行榜