Results 1 to 4 of 4
  1. #1
    peteosmith is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default Illegal start of type

    I am trying to run a simple swing application to show within a label on a frame a counter that goes to 50 using SwingWorker.
    I am using Netbeans, which shows illegal start of type - (I have indicated the line with a comment)

    Many thanks for any help!

    Java Code:
    import javax.swing.SwingWorker;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * concTest.java
     *
     * Created on Aug 13, 2011, 2:07:41 PM
     */
    /**
     *
     * @author Pete Smith
     */
    public class concTest extends javax.swing.JFrame {
    
    
        /** Creates new form concTest */
        public concTest() {
            initComponents();
        }
    
        /** 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")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jLabel1 = new javax.swing.JLabel();
            outputText = new javax.swing.JLabel();
            goButton = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jLabel1.setText("value");
    
            outputText.setText("Results");
    
            goButton.setText("Go");
            goButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    goButtonActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(23, 23, 23)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(goButton)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(outputText, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(44, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(outputText, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(34, 34, 34)
                    .addComponent(goButton)
                    .addContainerGap(210, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>
    private static class theNumber {
          private final int value;
          theNumber(int inValue){
              value = inValue;
          }
      }  
    //THE FOLLOWING LINE INDICATES AN ILLEGAL START OF TYPE
    private class valueTask extends SwingWorker<void, theNumber> {          
    
          @Override
          protected Void doInBackground() {
              int counter = 0;
              while (counter <= 50) {
                  publish(new theNumber(counter));
              counter++;
               }
              return null;
          }
          @Override
          protected void process(List<theNumber> numbers) {
              outputText.setText(numbers.value);
          }
          
      }
    
      
    
    
        
    private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {
        valueTask task = new valueTask().execute();
    }
     
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url] 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(concTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(concTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(concTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(concTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new concTest().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton goButton;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel outputText;
        // End of variables declaration
    }
    Last edited by Fubarable; 08-13-2011 at 04:53 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Welcome to the forum. I've added code tags to help make your code retain its formatting and thereby be more readable.

    As for your problem, one issue is that a SwingWorker's generic type must by Void, not void.

    So don't do this:

    Java Code:
    private class valueTask extends SwingWorker<void, theNumber> {
    But rather do this:


    Java Code:
    private class valueTask extends SwingWorker<Void, theNumber> {

  3. #3
    peteosmith is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks for that - sometimes it requires another eye to see the obvious - Void not void - did the trick!
    Thanks!!!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're welcome. There are other problems in the code, but I'll let you try to solve them first. :)

Similar Threads

  1. illegal start of expression
    By minusten in forum New To Java
    Replies: 1
    Last Post: 05-03-2011, 04:46 AM
  2. Illegal start of expression
    By Tekila in forum New To Java
    Replies: 10
    Last Post: 03-04-2011, 12:23 AM
  3. <identifier> expected, illegal start of type
    By masberry in forum New To Java
    Replies: 1
    Last Post: 11-02-2009, 07:45 PM
  4. Illegal Start of an Expression
    By ddatta8 in forum New To Java
    Replies: 3
    Last Post: 12-20-2008, 08:40 PM
  5. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •