Results 1 to 4 of 4
Thread: ';' expected error
- 05-03-2011, 05:19 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 28
- Rep Power
- 0
';' 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 05:22 AM. Reason: correct title of error
- 05-03-2011, 05:23 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Look closely at your opening and closing parentheses on that line.
- 05-03-2011, 07:42 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 28
- Rep Power
- 0
Ok, got it. 1 too many )..thank you
- 05-03-2011, 07:51 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
-
Error:identifier expected(Help!)
By chhoton in forum New To JavaReplies: 8Last Post: 09-22-2009, 04:42 PM -
Error: ')' expected
By baltimore in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:32 AM -
Error: '{' expected
By romina in forum New To JavaReplies: 1Last Post: 07-26-2007, 09:34 AM -
My error is: ')' expected
By silvia in forum New To JavaReplies: 1Last Post: 07-18-2007, 04:49 PM -
MSG ERROR: : expected
By Marty in forum New To JavaReplies: 1Last Post: 05-31-2007, 02:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks