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));
}
java loops user-interface
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.
add a comment |
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));
}
java loops user-interface
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
add a comment |
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));
}
java loops user-interface
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
java loops user-interface
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
add a comment |
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
add a comment |
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]) {
add a comment |
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);
add a comment |
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]) {
add a comment |
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]) {
add a comment |
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]) {
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]) {
answered yesterday
Thomas Kläger
5,4592617
5,4592617
add a comment |
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
edited yesterday
answered yesterday
Max7CD
316
316
add a comment |
add a comment |
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