我的代码给了我错误,不确定是什么问题 [英] my code giving me errors not sure what is wrong

查看:80
本文介绍了我的代码给了我错误,不确定是什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 LinkedList SongList =  new  LinkedList(); 
jbtDisplay.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
disp.setText( );
for int index = 1 ; index < = SongList.getLength(); index ++){
disp.append( 条目编号\t: + index + < span class =code-string> \ n + SongList.getEntry(index)+ \ n \\ n);
}
updateEntry();
}
});

解决方案

HI,



您可以使用

 SongList.size();  in  getlength()和
SongList。 get (index) getEntry ()并查看如果它解决问题并达到目的


HI



您可以使用以下代码,看看它是否符合要求





< pre lang =cs> LinkedList SongList = new LinkedList();
jbtDisplay.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
disp.setText( );
for int index = 1 ; index < = SongList.size(); index ++){
disp.append( 条目编号\t: + index + < span class =code-string> \ n + SongList。 get (index)+ \ n \ n);
}
updateEntry();
}
} );


它是否给你和IndexOutOfBoundsException?如果是这样,请尝试下一件事:index< songlist.size()>< =这意味着程序将尝试访问额外的元素。





祝你好运。


 LinkedList SongList=new LinkedList();
jbtDisplay.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
                           disp.setText("");
            for(int index =1; index <= SongList.getLength(); index++){
                disp.append("Entry number\t:" + index + "\n" + SongList.getEntry(index) + "\n\n");
            }
                updateEntry();
         }
       });

解决方案

HI,

You could use the

SongList.size();in place of getlength()and 
        SongList.get(index) for getEntry() and see if it resolves the issue and serves the purpose


HI

You could use the following code and see if it serves the purpose


LinkedList SongList=new LinkedList();
jbtDisplay.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
                           disp.setText("");
            for(int index =1; index <= SongList.size();index++){
                disp.append("Entry number\t:" + index + "\n" + SongList.get(index) + "\n\n");
            }
                updateEntry();
         }
       });.


Is it giving you and IndexOutOfBoundsException ? If that so try the next thing: index<songlist.size()><= it means that the program will try to access an extra element.


Best regards.


这篇关于我的代码给了我错误,不确定是什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆