Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 09:40 PM
Member
 
Join Date: Jul 2007
Posts: 40
baltimore is on a distinguished road
Syntax error on token "(", ; expected
Hi, I can't seem to figure out a syntax error. Here is some stuff for background. I am using Eclipse 3.0.1 IDE and I downloaded Java 5 Update 1 JDK from Sun and installed both (note I installed Eclipse first, not sure if it matters). Windows XP SP2.

Eclipse is showing this error...
Code:
Syntax error on token "(", ; expected Syntax error on token ")", ; expected
for the following code.(line 21)

The IDE underlines the () that I put in RED and says the error is there. I don't get it because I don't think I need a ; anywhere. (and this code is copied directly from my prof's website)

Thanks for any help, really really new to java, I hope it is something simple.

Code:
package edu.uwec.cs.muellerzabel.conversion; import javax.swing.JOptionPane; public class Convert { public static void main(String[] args) { private static double getDouble(string prompt) { double x = 0; boolean done = false; while (!done) { try { x = Double.parseDouble(JOptionPane.showInputDialog(prompt)); done = true; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "That wasn't a valid input. Please enter a number."); } } return x; } double dblUserInput = 0; double dblEnglish = 0; double dblFeet = 0; double dblInches = 0; dblUserInput = getDouble("Enter the number of meters you would like to convert to feet or inches."); dblEnglish = dblUserInput * 39.37; dblFeet = dblEnglish / 12; dblInches = dblEnglish; if (dblEnglish > 12){ JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblFeet + " feet."); }else { JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblInches + " inches."); } } }
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-01-2007, 12:34 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
hardwired is on a distinguished road
You had the getDouble method inside the main method. This confuses the compiler.
Also, the type (string) in the getDouble argument (string prompt) should be capitalized, viz, "String prompt".
This compiles okay:
Code:
package edu.uwec.cs.muellerzabel.conversion; import javax.swing.JOptionPane; public class Convert { public static void main(String[] args) { double dblUserInput = 0; double dblEnglish = 0; double dblFeet = 0; double dblInches = 0; dblUserInput = getDouble("Enter the number of meters you would " + "like to convert to feet or inches."); dblEnglish = dblUserInput * 39.37; dblFeet = dblEnglish / 12; dblInches = dblEnglish; if (dblEnglish > 12){ JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblFeet + " feet."); } else { JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblInches + " inches."); } } private static double getDouble(String prompt) { double x = 0; boolean done = false; while (!done) { try { x = Double.parseDouble(JOptionPane.showInputDialog(prompt)); done = true; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "That wasn't a valid input. Please enter a number."); } } return x; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to solve "No compiler error"? iceman New To Java 5 04-22-2008 04:37 AM
"Cannont find symbol Constructor" error Welsh New To Java 7 01-25-2008 01:12 AM
Strange error message "Source not found" ppayal Eclipse 0 11-25-2007 07:19 PM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 08:53 AM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-25-2007 11:55 PM


All times are GMT +3. The time now is 01:07 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org