我不知道为什么在test.charAt(1)处索引超出范围

时间:2020-05-13 08:51:07

标签: java indexoutofboundsexception

void PictureBox2Click(object sender, EventArgs e)
        {

            pictureBox14.Location= new Point(440,50);
            pictureBox2.BackgroundImage = olikakort[färg];
            System.Threading.Thread.Sleep(2000);
            pictureBox14.SendToBack();

        }

线程“ main”中的异常java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:1 我不知道为什么索引超出范围,请帮忙。我正在尝试编写一个对消息进行加密的程序

2 个答案:

答案 0 :(得分:1)

String test = array[j];仅采用数组的第j个字符,而执行test.charAt(1)将使代码失败。围绕它写一些打印语句以进一步调试

答案 1 :(得分:0)

在访问该位置的字符之前先添加支票

private void Button_Click(object sender, RoutedEventArgs e)
{
    //what you want to do on the filter click
}