Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的循环GUI不断出错有人知道这个问题吗?_Java_Loops_User Interface - Fatal编程技术网

Java 我的循环GUI不断出错有人知道这个问题吗?

Java 我的循环GUI不断出错有人知道这个问题吗?,java,loops,user-interface,Java,Loops,User Interface,有人知道我的代码有什么问题吗?它在JavaGUI中不断得到错误输出 调试后,循环2和循环3出现错误,我不知道出了什么问题 private void butActionPerformed(java.awt.event.ActionEvent evt) { String input1 = txtInput.getText(); String input2 = input1.toLowerCase();

有人知道我的代码有什么问题吗?它在JavaGUI中不断得到错误输出 调试后,循环2和循环3出现错误,我不知道出了什么问题

 private void butActionPerformed(java.awt.event.ActionEvent evt) {                                    
    String input1 = txtInput.getText();
    String input2 = input1.toLowerCase();
    char[] word1 = new char[input2.length()];
    char[] word2 = new char[26];
    for (int i = 0; i < word2.length; i++) {
        word2[i] = (char) (97 + i);
    }
    int[] x = new int[26];
    for (int i = 0; i < word1.length; i++) {
        input1[i] = input2.charAt(i);
    }
    for (int i = 0; i < word2.length; i++) {
        for (int j = 0; j < word1.length; j++) {
            if (word2[i])==word1[j]) {
                x[i]++;
            }

        }

    }
    txtOutput1.setText(Arrays.toString(word2));
    txtOutput2.setText(Arrays.toString(x));
}               
input1是一个字符串变量,因此是不可变的,这意味着只能为其分配一个新值,否则无法对其进行更改

以下行导致出现问题:

input1[i] = input2.charAt(i);
第一个问题:

input1是字符串,但input1[i]=input2.charAti;您将其视为一个数组-这在Java中是不允许的

根据你的逻辑,我认为相应的行应该是

word1[i] = input2.charAt(i);
第二个问题:在线

if (word2[i])==word1[j]) {
在单词2[i]后面有一个右括号,该行应为

if (word2[i]==word1[j]) {

你到底得到了什么错误?@Pshemo第11行和第15行的循环后的行,以及第11行和第15行的内容,我们不知道在你发布的内容之前是否还有其他行可能影响行数计算?此外,如果问题发生在编译时,您还需要回答问题并包含错误消息;如果问题发生在运行代码时,您还需要包含异常stacktrace。1要更快获得更好的帮助,请发布或。2始终复制/粘贴错误和异常输出!