title: Java Netbeans For loop error: cannot find symbol class, <identifier> expected?
body: <p>I'm making a hangman game and this is my current code:</p>
  
  <pre><code>//Declaring the array
      String [] WordList = {"anonymous", "tolerate", "appreciation", "commissioner", "harm", "flexibility", "instructional", "scramble", "casino", "tumor"};
  
  // Getting a random word for the game
  int num = ((int)Math.ceil(Math.random()*(WordList.length)));
  String word = WordList[num];
  
  // The puzzle to be displayed for the user to guess
  int letters = word.length();
  String hiddenWord = "";
  for (int i=0; i&lt;letters; i++){
      hiddenWord+="-";
  }
  </code></pre>
  
  <p>At the for loop, I get an error saying 'illegal start of type, cannot find symbol: class i'. 'i' is supposed to be an integer, which I've already declared, so I'm not sure why it's asking for a class. 
  There's also another error saying, 'identifier expected' and that there's a missing >. As my &lt; is meant to be used as comparison (and not as a declaration or identifier), I don't understand this error. </p>
  
  <p>For clarification, I should add that this is a desktop application in netbeans. The code is located after the line:</p>
  
  <pre><code>public class HangmanGameView extends FrameView {
  </code></pre>
  
  <p>Most of the rest of my code will be located within the actionPerformed code for my buttons. I need to be able to access the word and hiddenWord variables from within the code for the buttons, which is why I've put them here. I'm not positive if that's the problem as of yet. I'm also not sure where to put the code otherwise; there is no main method as far as I can see. </p>
  
  <p>Edit: I hadn't posted the complete code because this is all I've done for now; the rest is all auto-generated by NetBeans, and I thought it wouldn't be relevant. But here it is: </p>
  
  <pre><code>/*
   * HangmanGameView.java
   */
  
  package hangmangame;
  
  import org.jdesktop.application.Action;
  import org.jdesktop.application.ResourceMap;
  import org.jdesktop.application.SingleFrameApplication;
  import org.jdesktop.application.FrameView;
  import org.jdesktop.application.TaskMonitor;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.Timer;
  import javax.swing.Icon;
  import javax.swing.JDialog;
  import javax.swing.JFrame;
  
  /**
   * The application's main frame.
   */
  public class HangmanGameView extends FrameView {
  
  //Declaring the array
  String [] WordList = {"anonymous", "tolerate", "appreciation", "commissioner", "harm", "flexibility", "instructional", "scramble", "casino", "tumor"};
  
  // Getting a random word for the game
  int num = ((int)Math.ceil(Math.random()*(WordList.length)));
  String word = WordList[num];
  
  // The puzzle to be displayed for the user to guess
  int letters = word.length();
  String hiddenWord = "";
  for (int i=0; i&lt;letters; i++){
      hiddenWord+="-";
  }
  
  
  public HangmanGameView(SingleFrameApplication app) {
  
      super(app);
  
      initComponents();
  
      // status bar initialization - message timeout, idle icon and busy animation, etc
      ResourceMap resourceMap = getResourceMap();
      int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
      messageTimer = new Timer(messageTimeout, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              statusMessageLabel.setText("");
          }
      });
      messageTimer.setRepeats(false);
      int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
      for (int i = 0; i &lt; busyIcons.length; i++) {
          busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
      }
      busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
              statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
          }
      });
      idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
      statusAnimationLabel.setIcon(idleIcon);
      progressBar.setVisible(false);
  
      // connecting action tasks to status bar via TaskMonitor
      TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
      taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
          public void propertyChange(java.beans.PropertyChangeEvent evt) {
              String propertyName = evt.getPropertyName();
              if ("started".equals(propertyName)) {
                  if (!busyIconTimer.isRunning()) {
                      statusAnimationLabel.setIcon(busyIcons[0]);
                      busyIconIndex = 0;
                      busyIconTimer.start();
                  }
                  progressBar.setVisible(true);
                  progressBar.setIndeterminate(true);
              } else if ("done".equals(propertyName)) {
                  busyIconTimer.stop();
                  statusAnimationLabel.setIcon(idleIcon);
                  progressBar.setVisible(false);
                  progressBar.setValue(0);
              } else if ("message".equals(propertyName)) {
                  String text = (String)(evt.getNewValue());
                  statusMessageLabel.setText((text == null) ? "" : text);
                  messageTimer.restart();
              } else if ("progress".equals(propertyName)) {
                  int value = (Integer)(evt.getNewValue());
                  progressBar.setVisible(true);
                  progressBar.setIndeterminate(false);
                  progressBar.setValue(value);
              }
          }
      });
  }
  
  @Action
  public void showAboutBox() {
      if (aboutBox == null) {
          JFrame mainFrame = HangmanGameApp.getApplication().getMainFrame();
          aboutBox = new HangmanGameAboutBox(mainFrame);
          aboutBox.setLocationRelativeTo(mainFrame);
      }
      HangmanGameApp.getApplication().show(aboutBox);
  }
  
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;
  private void initComponents() {
  
      mainPanel = new javax.swing.JPanel();
      titleLabel = new javax.swing.JLabel();
      startButton = new javax.swing.JButton();
      guesswordOutput = new javax.swing.JLabel();
      guessLabel = new javax.swing.JLabel();
      guessInput = new javax.swing.JTextField();
      guessButton = new javax.swing.JButton();
      picLabel = new javax.swing.JLabel();
      jScrollPane1 = new javax.swing.JScrollPane();
      gameOutput = new javax.swing.JTextArea();
      menuBar = new javax.swing.JMenuBar();
      javax.swing.JMenu fileMenu = new javax.swing.JMenu();
      javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
      javax.swing.JMenu helpMenu = new javax.swing.JMenu();
      javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
      statusPanel = new javax.swing.JPanel();
      javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
      statusMessageLabel = new javax.swing.JLabel();
      statusAnimationLabel = new javax.swing.JLabel();
      progressBar = new javax.swing.JProgressBar();
  
      org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(hangmangame.HangmanGameApp.class).getContext().getResourceMap(HangmanGameView.class);
      mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
      mainPanel.setName("mainPanel"); // NOI18N
  
      titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getSize()+19f));
      titleLabel.setForeground(resourceMap.getColor("titleLabel.foreground")); // NOI18N
      titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      titleLabel.setText(resourceMap.getString("titleLabel.text")); // NOI18N
      titleLabel.setName("titleLabel"); // NOI18N
  
      startButton.setFont(startButton.getFont().deriveFont(startButton.getFont().getStyle() &amp; ~java.awt.Font.BOLD, startButton.getFont().getSize()+5));
      startButton.setForeground(resourceMap.getColor("startButton.foreground")); // NOI18N
      startButton.setText(resourceMap.getString("startButton.text")); // NOI18N
      startButton.setToolTipText(resourceMap.getString("startButton.toolTipText")); // NOI18N
      startButton.setName("startButton"); // NOI18N
      startButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              startButtonActionPerformed(evt);
          }
      });
  
      guesswordOutput.setText(resourceMap.getString("guesswordOutput.text")); // NOI18N
      guesswordOutput.setName("guesswordOutput"); // NOI18N
  
      guessLabel.setFont(resourceMap.getFont("guessLabel.font")); // NOI18N
      guessLabel.setText(resourceMap.getString("guessLabel.text")); // NOI18N
      guessLabel.setName("guessLabel"); // NOI18N
  
      guessInput.setBackground(resourceMap.getColor("guessInput.background")); // NOI18N
      guessInput.setFont(resourceMap.getFont("guessInput.font")); // NOI18N
      guessInput.setText(resourceMap.getString("guessInput.text")); // NOI18N
      guessInput.setToolTipText(resourceMap.getString("guessInput.toolTipText")); // NOI18N
      guessInput.setName("guessInput"); // NOI18N
  
      guessButton.setFont(resourceMap.getFont("guessButton.font")); // NOI18N
      guessButton.setForeground(resourceMap.getColor("guessButton.foreground")); // NOI18N
      guessButton.setText(resourceMap.getString("guessButton.text")); // NOI18N
      guessButton.setName("guessButton"); // NOI18N
      guessButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              guessButtonActionPerformed(evt);
          }
      });
  
      picLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      picLabel.setIcon(resourceMap.getIcon("picLabel.icon")); // NOI18N
      picLabel.setText(resourceMap.getString("picLabel.text")); // NOI18N
      picLabel.setName("picLabel"); // NOI18N
  
      jScrollPane1.setName("jScrollPane1"); // NOI18N
  
      gameOutput.setBackground(resourceMap.getColor("gameOutput.background")); // NOI18N
      gameOutput.setColumns(20);
      gameOutput.setRows(5);
      gameOutput.setName("gameOutput"); // NOI18N
      jScrollPane1.setViewportView(gameOutput);
  
      javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
      mainPanel.setLayout(mainPanelLayout);
      mainPanelLayout.setHorizontalGroup(
          mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(titleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
          .addGroup(mainPanelLayout.createSequentialGroup()
              .addGap(42, 42, 42)
              .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                  .addGroup(mainPanelLayout.createSequentialGroup()
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                      .addComponent(picLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGroup(mainPanelLayout.createSequentialGroup()
                      .addComponent(guessLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(18, 18, 18)
                      .addComponent(guessInput, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(46, 46, 46)
                      .addComponent(guessButton)))
              .addContainerGap(55, Short.MAX_VALUE))
          .addGroup(mainPanelLayout.createSequentialGroup()
              .addGap(181, 181, 181)
              .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(189, Short.MAX_VALUE))
          .addComponent(guesswordOutput, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
      );
      mainPanelLayout.setVerticalGroup(
          mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(mainPanelLayout.createSequentialGroup()
              .addGap(21, 21, 21)
              .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(18, 18, 18)
              .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(26, 26, 26)
              .addComponent(guesswordOutput, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(38, 38, 38)
              .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(guessLabel)
                  .addComponent(guessButton)
                  .addComponent(guessInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
              .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(jScrollPane1)
                  .addComponent(picLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
              .addGap(39, 39, 39))
      );
  
      menuBar.setName("menuBar"); // NOI18N
  
      fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
      fileMenu.setName("fileMenu"); // NOI18N
  
      javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(hangmangame.HangmanGameApp.class).getContext().getActionMap(HangmanGameView.class, this);
      exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
      exitMenuItem.setName("exitMenuItem"); // NOI18N
      fileMenu.add(exitMenuItem);
  
      menuBar.add(fileMenu);
  
      helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
      helpMenu.setName("helpMenu"); // NOI18N
  
      aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
      aboutMenuItem.setName("aboutMenuItem"); // NOI18N
      helpMenu.add(aboutMenuItem);
  
      menuBar.add(helpMenu);
  
      statusPanel.setName("statusPanel"); // NOI18N
  
      statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
  
      statusMessageLabel.setName("statusMessageLabel"); // NOI18N
  
      statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
      statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
  
      progressBar.setName("progressBar"); // NOI18N
  
      javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
      statusPanel.setLayout(statusPanelLayout);
      statusPanelLayout.setHorizontalGroup(
          statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
          .addGroup(statusPanelLayout.createSequentialGroup()
              .addContainerGap()
              .addComponent(statusMessageLabel)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 315, Short.MAX_VALUE)
              .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
              .addComponent(statusAnimationLabel)
              .addContainerGap())
      );
      statusPanelLayout.setVerticalGroup(
          statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(statusPanelLayout.createSequentialGroup()
              .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(statusMessageLabel)
                  .addComponent(statusAnimationLabel)
                  .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGap(3, 3, 3))
      );
  
      setComponent(mainPanel);
      setMenuBar(menuBar);
      setStatusBar(statusPanel);
  }// &lt;/editor-fold&gt;
  
  private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
      // Initializes the game and displays the empty word for the player
  
  }
  
  private void guessButtonActionPerformed(java.awt.event.ActionEvent evt) {
      // TODO add your handling code here:
  }
  
  // Variables declaration - do not modify
  private javax.swing.JTextArea gameOutput;
  private javax.swing.JButton guessButton;
  private javax.swing.JTextField guessInput;
  private javax.swing.JLabel guessLabel;
  private javax.swing.JLabel guesswordOutput;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JPanel mainPanel;
  private javax.swing.JMenuBar menuBar;
  private javax.swing.JLabel picLabel;
  private javax.swing.JProgressBar progressBar;
  private javax.swing.JButton startButton;
  private javax.swing.JLabel statusAnimationLabel;
  private javax.swing.JLabel statusMessageLabel;
  private javax.swing.JPanel statusPanel;
  private javax.swing.JLabel titleLabel;
  // End of variables declaration
  
  private final Timer messageTimer;
  private final Timer busyIconTimer;
  private final Icon idleIcon;
  private final Icon[] busyIcons = new Icon[15];
  private int busyIconIndex = 0;
  
  private JDialog aboutBox;
  }
  </code></pre>
  
  <p>Final Edit:
  I moved my for loop to inside the start button code - leaving the initial declaration of the hiddenWord string at the beginning - and it's working fine now. Thanks for the help!</p>