Skip to main content

Annotation error?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2013-10-02

Hi,... I am new to Java programming. My last learned programming language was Turbo Pascal 6.0 ... So it has been a while for me. ;-D

Im following a course in java via a homelearning institute that uses the book "Head First Java" as a guide. I'm almost finished with chapter 3, and I was given the task to write a small programm.

After the several lines of code, Eclipse says I have made an annotation mistake. The ';' behind my String declaration should be a ','!
I think it has to do something with the import of javax line, as this only occurence when I have typed in the JOptionPane line. But I cant figure out what is going wrong.

The code below is all I have sofar. I have not made a main yet. I wish to know why Eclipse generates this error, else typing in all the other code would be pointless

Here is the small code sofar, if somebody decides to help me out.

Thanks already!

----------------( Code)------------------

package hoofdstuk3;

import javax.swing.JOptionPane;

public class WachtwoordControle {

String geheimWW = "javaiskoffie";
String invoerWW = ""; // here Eclipse says the ';' should be a ',' ???

invoerWW = JOptionPane.showInputDialog(null, "Voer een wachtwoord in", "Invoerscherm", JOptionPane.QUESTION_MESSAGE);


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2013-10-02

It suddenly worked once I removed the first InvoerWW declaration and added 'String' to the line where the input is suppose to be:

String invoerWW = JOptionPane.showInputDialog(null, "Voer een wachtwoord in", "Invoerscherm", JOptionPane.QUESTION_MESSAGE);

But I still do not get it. It worked like I first tried it, in another program, just fine. The only difference with that program was that it was in a main. That program looked like this:
import javax.swing.JOptionPane;
public class CijferProgramma {
public static void main(String[] args) {
String cijfer_invoer = "";
int cijfer=10;

while (cijfer!=0) {
String resultaat="";
cijfer_invoer = JOptionPane.showInputDialog(null, "Voer een cijfer in (0 voor exit)", "invoerscherm", JOptionPane.QUESTION_MESSAGE);
... ... ...

What is the difference, when it is in a main or not?
Why can I declare cijfer_invoer in the 2nd program ahead of time,... while I can only declare invoerWW in the line where I will first use it, in the 1st program?