Results 1 to 4 of 4
  1. #1
    collwill is offline Member
    Join Date
    Mar 2011
    Posts
    28
    Rep Power
    0

    Default ';' expected error

    Trying to compile and getting error: ';' expected. Class is ending in 2 weeks and guess I am going crossed eyed looking at codes and trying to see what I am missing. Please could somone please help me with this. Also is it valid to create an array in showElement class? Code is suppose to allow user input index and find value. It is also suppsoe to catch out bounds index and non interger. Any help to finding my mistake would be greatly appreciated. This is the only class I will be taking and need it for a business class.

    Java Code:
    import java.lang.*;
    import java.util.Random;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Program13a extends JFrame
    {
        private JLabel indexLabel;
        private JLabel valueLabel;
        private JTextField arrayIndex;
        private JTextField arrayValue;
        private JButton showElement;
        private JPanel panel;
        private JPanel statusPanel;
        private JLabel statusLine;
        private int randomNumber[];
    
        public Program13a()
        {
             indexLabel = new JLabel("Input Array Index:");
            arrayIndex = new JTextField(10);
            valueLabel = new JLabel("Array Element Value:");
            arrayValue = new JTextField(10);//
            showElement = new JButton("Show Element");//
            showElement.addActionListener(new showElement());//
            arrayValue.setEditable(false);
    
            panel = new JPanel ();
            panel.add(indexLabel);
            panel.add(valueLabel);
            panel.add(arrayIndex);
            panel.add(arrayValue);
            panel.add(showElement);
            statusPanel.add(statusLine);
    
            Container contentPane = getContentPane();
    		contentPane.add(panel, BorderLayout.CENTER);
    		contentPane.add(statusPanel, BorderLayout.PAGE_END);
        }
    
    public class showElement implements ActionListener{
    	public void actionPerformed(ActionEvent e){
    
    	             int [] randomNumber = new int [100];
    		    for (int x = 0; x < numbers.length; x++)
    		     randomNumber[x] = (int)(Math.random()) * 1000);///this is the line I get the error
    
    		   String inputString;
    		   inputString=statusLine.getText();
    		   try{
    			randomNumber = Integer.parseInt(inputString);	statusLine.setText("");
    			}
    
    			catch (IndexOutOfBoundsException ex){
    				statusLine.setText("Out of bounds");
    			}
    
    			catch (NumberFormatException ex)
    			{
    				statusLine.setText("Not a Integer.");
    			}
    
    	}
    }
    	public static void main(String[] args)
        {
        	Program13 frame = new Program13 ();
            frame.setTitle("Random Array");
            frame.setSize(600,500);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    
    }
    Last edited by collwill; 05-03-2011 at 06:22 AM. Reason: correct title of error

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Look closely at your opening and closing parentheses on that line.

  3. #3
    collwill is offline Member
    Join Date
    Mar 2011
    Posts
    28
    Rep Power
    0

    Default

    Ok, got it. 1 too many )..thank you

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are welcome, glad to have helped you out. Any time you see that error really scrutinize the lines around the exceptions. It's almost always a silly syntax error or a missed semi-colon.

Similar Threads

  1. Error:identifier expected(Help!)
    By chhoton in forum New To Java
    Replies: 8
    Last Post: 09-22-2009, 05:42 PM
  2. Error: ')' expected
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:32 AM
  3. Error: '{' expected
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-26-2007, 10:34 AM
  4. My error is: ')' expected
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 05:49 PM
  5. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:21 AM

Posting Permissions

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