Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求教高手啊(ArrayIndexOutOfBoundsException)
jfs771





发贴: 8
积分: 0
于 2005-04-19 14:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请尽量用准确的文字描述作为标题

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


话题树型展开
人气 标题 作者 字数 发贴时间
9213 求教高手啊(ArrayIndexOutOfBoundsException) jfs771 1979 2005-04-19 14:59
7454 Re:求教高手啊。。。。。 bluepure 323 2005-04-19 17:30
7518 Re:求教高手啊。。。。。 jfs771 221 2005-04-19 19:14
7393 Re:求教高手啊(ArrayIndexOutOfBoundsException) xiaoshitou 93 2005-05-11 15:56
7978 Re:求教高手啊(ArrayIndexOutOfBoundsException) undefined 2518 2005-05-12 19:59
9456 Re:求教高手啊(ArrayIndexOutOfBoundsException) undefined 571 2005-05-12 20:10
8000 Re:求教高手啊(ArrayIndexOutOfBoundsException) jfs771 31 2005-05-18 10:37

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923