jfs771
发贴: 8
积分: 0
|
于 2005-04-19 14:59
请尽量用准确的文字描述作为标题
public class Attributes { private byte type; private byte length; private byte[] value=null; //不定长
public Attributes(int typ,String value){ this.type=(byte)typ;
this.value=value.getBytes(); }
int getlength(){ return value.length+2; }
byte[] tobyte(){
byte[] newbyte=new byte[this.getlength()]; newbyte[0]=this.type; newbyte[1]=this.length; for(int i=0;i<this.getlength()-1;i++){ newbyte[i+2]=this.value[i];} return newbyte; } }
public class DAFrame { private byte code; private byte identifier; private byte length[]=new byte[2]; private byte Authenticator[]=new byte[16]; private Attributes attributes; public DAFrame(int code,int i,byte[] authen,Attributes attri) { this.code=(byte)code; this.identifier=(byte)i; this.setlength(); this.Authenticator=authen; this.attributes=attri; }
void setlength(){ this.length[0]=(byte)this.getlength(); int length1=this.getlength(); length1=length1/256 this.length[1]=(byte)length1; }
int getlength(){ return 20+this.attributes.getlength(); }
byte[] tobyte(){ byte[] newbyte=new byte[this.getlength()]; newbyte[0]=this.code; newbyte[1]=this.identifier; newbyte[2]=this.length[0]; newbyte[3]=this.length[1]; for(int i=0;i<17;i++){ newbyte[i+4]=this.Authenticator[i]; } //错误处 byte[] attribyte=this.attributes.tobyte(); for(int i=0;i<attribyte.length;i++){ newbyte[i+20]=attribyte[i]; } return newbyte; }
}
tobyte的本意是将类中的各个数据域连接起来组成一个新的byte数组
在程序中调用DAFrame的tobyte方法时出现错误 java.lang.ArrayIndexOutOfBoundsException: 16 at rasclient.DAFrame.tobyte(DAFrame.java:82) 剩下的15处都是由这个引起的。。
本人的JAVA基本功实在是差的,由于毕设,才接触了两三个星期, 使用的Jbuilder9。 高手的给讲讲啊,或者给改改。小弟在此不胜感激!!!!
why edited on 2005-04-19 19:17
|