My loop GUI keep getting error does anyone know the problem? [on hold]











up vote
-1
down vote

favorite












does anyone know whats wrong with my code? it keep getting error output in java GUI
the loop 2 and loop 3 getting error after debug, and i dont know whats wrong



 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));
}









share|improve this question













put on hold as off-topic by Reimeus, Pshemo, Andrew Thompson, Stephen C, David Makogon yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Reimeus, Pshemo, Andrew Thompson, Stephen C

If this question can be reworded to fit the rules in the help center, please edit the question.













  • What errors you are getting exactly?
    – Pshemo
    yesterday










  • @Pshemo the line after the loop for in line 11 and line 15
    – Hensel
    yesterday






  • 2




    And what is at line 11 and 15 (we don't know if there are some other lines before what you posted which may affect line numeration)? Also you still need to edit your question and include error message (if it happens at compilation) or exception stacktrace (if it happens while running your code).
    – Pshemo
    yesterday












  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Always copy/paste error and exception output!
    – Andrew Thompson
    yesterday















up vote
-1
down vote

favorite












does anyone know whats wrong with my code? it keep getting error output in java GUI
the loop 2 and loop 3 getting error after debug, and i dont know whats wrong



 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));
}









share|improve this question













put on hold as off-topic by Reimeus, Pshemo, Andrew Thompson, Stephen C, David Makogon yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Reimeus, Pshemo, Andrew Thompson, Stephen C

If this question can be reworded to fit the rules in the help center, please edit the question.













  • What errors you are getting exactly?
    – Pshemo
    yesterday










  • @Pshemo the line after the loop for in line 11 and line 15
    – Hensel
    yesterday






  • 2




    And what is at line 11 and 15 (we don't know if there are some other lines before what you posted which may affect line numeration)? Also you still need to edit your question and include error message (if it happens at compilation) or exception stacktrace (if it happens while running your code).
    – Pshemo
    yesterday












  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Always copy/paste error and exception output!
    – Andrew Thompson
    yesterday













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











does anyone know whats wrong with my code? it keep getting error output in java GUI
the loop 2 and loop 3 getting error after debug, and i dont know whats wrong



 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));
}









share|improve this question













does anyone know whats wrong with my code? it keep getting error output in java GUI
the loop 2 and loop 3 getting error after debug, and i dont know whats wrong



 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));
}






java loops user-interface






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Hensel

42




42




put on hold as off-topic by Reimeus, Pshemo, Andrew Thompson, Stephen C, David Makogon yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Reimeus, Pshemo, Andrew Thompson, Stephen C

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Reimeus, Pshemo, Andrew Thompson, Stephen C, David Makogon yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Reimeus, Pshemo, Andrew Thompson, Stephen C

If this question can be reworded to fit the rules in the help center, please edit the question.












  • What errors you are getting exactly?
    – Pshemo
    yesterday










  • @Pshemo the line after the loop for in line 11 and line 15
    – Hensel
    yesterday






  • 2




    And what is at line 11 and 15 (we don't know if there are some other lines before what you posted which may affect line numeration)? Also you still need to edit your question and include error message (if it happens at compilation) or exception stacktrace (if it happens while running your code).
    – Pshemo
    yesterday












  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Always copy/paste error and exception output!
    – Andrew Thompson
    yesterday


















  • What errors you are getting exactly?
    – Pshemo
    yesterday










  • @Pshemo the line after the loop for in line 11 and line 15
    – Hensel
    yesterday






  • 2




    And what is at line 11 and 15 (we don't know if there are some other lines before what you posted which may affect line numeration)? Also you still need to edit your question and include error message (if it happens at compilation) or exception stacktrace (if it happens while running your code).
    – Pshemo
    yesterday












  • 1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Always copy/paste error and exception output!
    – Andrew Thompson
    yesterday
















What errors you are getting exactly?
– Pshemo
yesterday




What errors you are getting exactly?
– Pshemo
yesterday












@Pshemo the line after the loop for in line 11 and line 15
– Hensel
yesterday




@Pshemo the line after the loop for in line 11 and line 15
– Hensel
yesterday




2




2




And what is at line 11 and 15 (we don't know if there are some other lines before what you posted which may affect line numeration)? Also you still need to edit your question and include error message (if it happens at compilation) or exception stacktrace (if it happens while running your code).
– Pshemo
yesterday






And what is at line 11 and 15 (we don't know if there are some other lines before what you posted which may affect line numeration)? Also you still need to edit your question and include error message (if it happens at compilation) or exception stacktrace (if it happens while running your code).
– Pshemo
yesterday














1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Always copy/paste error and exception output!
– Andrew Thompson
yesterday




1) For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example. 2) Always copy/paste error and exception output!
– Andrew Thompson
yesterday












2 Answers
2






active

oldest

votes

















up vote
1
down vote













The first problem:



input1 is a string, but with input1[i] = input2.charAt(i); you are treating it as an array - this is not allowed in Java.



From your logic I think the corresponding line should be



word1[i] = input2.charAt(i);




The second problem: on the line



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


there is a closing parenthesis to much (after word2[i]), the line should read



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





share|improve this answer




























    up vote
    0
    down vote













    input1 is a String variable and therefore immutable, which means it can only be assigned a new value and can not be changed otherwise.



    The following line causes a problem:



    input1[i] = input2.charAt(i);





    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      The first problem:



      input1 is a string, but with input1[i] = input2.charAt(i); you are treating it as an array - this is not allowed in Java.



      From your logic I think the corresponding line should be



      word1[i] = input2.charAt(i);




      The second problem: on the line



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


      there is a closing parenthesis to much (after word2[i]), the line should read



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





      share|improve this answer

























        up vote
        1
        down vote













        The first problem:



        input1 is a string, but with input1[i] = input2.charAt(i); you are treating it as an array - this is not allowed in Java.



        From your logic I think the corresponding line should be



        word1[i] = input2.charAt(i);




        The second problem: on the line



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


        there is a closing parenthesis to much (after word2[i]), the line should read



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





        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          The first problem:



          input1 is a string, but with input1[i] = input2.charAt(i); you are treating it as an array - this is not allowed in Java.



          From your logic I think the corresponding line should be



          word1[i] = input2.charAt(i);




          The second problem: on the line



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


          there is a closing parenthesis to much (after word2[i]), the line should read



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





          share|improve this answer












          The first problem:



          input1 is a string, but with input1[i] = input2.charAt(i); you are treating it as an array - this is not allowed in Java.



          From your logic I think the corresponding line should be



          word1[i] = input2.charAt(i);




          The second problem: on the line



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


          there is a closing parenthesis to much (after word2[i]), the line should read



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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Thomas Kläger

          5,4592617




          5,4592617
























              up vote
              0
              down vote













              input1 is a String variable and therefore immutable, which means it can only be assigned a new value and can not be changed otherwise.



              The following line causes a problem:



              input1[i] = input2.charAt(i);





              share|improve this answer



























                up vote
                0
                down vote













                input1 is a String variable and therefore immutable, which means it can only be assigned a new value and can not be changed otherwise.



                The following line causes a problem:



                input1[i] = input2.charAt(i);





                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  input1 is a String variable and therefore immutable, which means it can only be assigned a new value and can not be changed otherwise.



                  The following line causes a problem:



                  input1[i] = input2.charAt(i);





                  share|improve this answer














                  input1 is a String variable and therefore immutable, which means it can only be assigned a new value and can not be changed otherwise.



                  The following line causes a problem:



                  input1[i] = input2.charAt(i);






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  Max7CD

                  316




                  316















                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini