Java Syntax Error, Help Appreciated
- YettiSniper
-
YettiSniper
- Member since: Feb. 18, 2006
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
Alright I'm pretty new to Java but i can't figure out what's wrong with this code for the life of me. I've initialized all the variables in my program and imported javax.swing. Let me know if you need more specifics.
Error:
============================================= ==============================
Periodic_Table_Review.java:164: ')' expected
JOptionPane.showMessageDialog( null, "Sorry, the correct symbol for " + element[ref] + " is: " symbol[ref], "Incorrect Answer", JOptionPane.INFORMATION_MESSAGE );
============================================= ==============================
Thanks in advance for any help!
- amaterasu
-
amaterasu
- Member since: Mar. 7, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Apparently you are missing a ")" somewhere. Check your syntax around this line of code for any open parenthesis.
beep
- amaterasu
-
amaterasu
- Member since: Mar. 7, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
I'm sorry, let me elaborate. That line in particular is closed, so there must be a line before that which is missing a closure of the parenthesis.
beep
- YettiSniper
-
YettiSniper
- Member since: Feb. 18, 2006
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
Thanks for the idea but everything looks air tight to me :(
I'll post the entire method's code to give everyone a better idea of what im working with:
============================================= ===========================
public void actionPerformed( ActionEvent actionEvent )
{
String userAnswer = "";
userAnswer = guessField.getText();
switch(choice){
case 1:
if( userAnswer == symbol[ref] )
{
correct++;
JOptionPane.showMessageDialog( null, "Nice job!", "Correct Answer", JOptionPane.INFORMATION_MESSAGE );
}
else
{
incorrect++;
JOptionPane.showMessageDialog( null, "Sorry, the correct symbol for " + element[ref] + " is: " symbol[ref], "Incorrect Answer", JOptionPane.INFORMATION_MESSAGE );
}
elementQuestions();
break;
case 2:
if( userAnswer == element[ref] )
{
correct++;
JOptionPane.showMessageDialog( null, "Nice job!", "Correct Answer", JOptionPane.INFORMATION_MESSAGE );
}
else
{
incorrect++;
JOptionPane.showMessageDialog( null, "Sorry, the correct element for " + symbol[ref] + " is: " element[ref], "Incorrect Answer", JOptionPane.INFORMATION_MESSAGE );
}
symbolQuestions();
break;
case 3:
if( questionType == 0 )
{
if( userAnswer == symbol[ref] )
{
correct++;
JOptionPane.showMessageDialog( null, "Nice job!", "Correct Answer", JOptionPane.INFORMATION_MESSAGE );
}
else
{
incorrect++;
JOptionPane.showMessageDialog( null, "Sorry, the correct symbol for " + element[ref] + " is: " symbol[ref], "Incorrect Answer", JOptionPane.INFORMATION_MESSAGE );
}
mixedBag();
break;
}//end first if
else
{
if( userAnswer == element[ref] )
{
correct++;
JOptionPane.showMessageDialog( null, "Nice job!", "Correct Answer", JOptionPane.INFORMATION_MESSAGE );
}
else
{
incorrect++;
JOptionPane.showMessageDialog( null, "Sorry, the correct element for " + symbol[ref] + " is: " element[ref], "Incorrect Answer", JOptionPane.INFORMATION_MESSAGE );
}
mixedBag();
break;
}//end else
default:
JOptionPane.showMessageDialog( null, "Switch Select Error", "Error", JOptionPane.WARNING_MESSAGE );
} //end switch
}//end actionEvent()
============================================= ===========================
I get an error for each of my 4 JOptionPane.showMessageDialog statements that try to print a string from one of my string arrays . element[] and symbol[] are both string arrays and have already been intialized.
Thanks again to anyone who helps

