Results 1 to 4 of 4
- 07-31-2007, 08:40 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
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...
for the following code.(line 21)Java Code:Syntax error on token "(", ; expected Syntax error on token ")", ; expected
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.
Thanks.Java 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."); } } }
- 07-31-2007, 11:34 PM #2
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:
Java 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; } }
- 10-23-2009, 08:48 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
Syntax error on token "(", ; expected
Eclipse is showing this error...
Code:
Syntax error on token "(", ; expected
Syntax error on token ")", ; expected
line 11 and 15..
the following is my code:
import javax.jws.WebService;
@WebService
public class try2
{
String num1,num2;
public try2(){}
public String getNmbers()
{
final String getNumber1(String num1)
{
return num1;
}
final String getNumber2(String num2)
{
return num2;
}
}
}
please help me solving the errors in the above code..
- 10-28-2009, 12:19 AM #4
Compiling
givesJava Code:public class try2 { String num1,num2; public try2(){} public String getNmbers() { final String getNumber1(String num1) { return num1; } final String getNumber2(String num2) { return num2; } } }
Placing methods inside other methods gets the compiler confused.Java Code:C:\jexp>javac Try2.java Try2.java:9: ';' expected final String getNumber1(String num1) ^ Try2.java:9: ';' expected final String getNumber1(String num1) ^ Try2.java:13: ';' expected final String getNumber2(String num2) ^ Try2.java:13: ';' expected final String getNumber2(String num2) ^ 4 errors
Try something like this instead:
Java Code:public class Try2 { String num1,num2; public Try2(){} public String getNmbers() { return num1 + ", " + num2; } final String getNumber1() { return num1; } final String getNumber2() { return num2; } }
Similar Threads
-
Hwlp with "Open", "Save", "Save as..."
By trill in forum New To JavaReplies: 3Last Post: 11-02-2010, 09:26 AM -
How to solve "No compiler error"?
By iceman in forum New To JavaReplies: 5Last Post: 04-22-2008, 03:37 AM -
"Cannont find symbol Constructor" error
By Welsh in forum New To JavaReplies: 7Last Post: 01-25-2008, 12:12 AM -
Strange error message "Source not found"
By ppayal in forum EclipseReplies: 0Last Post: 11-25-2007, 06:19 PM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks

Bookmarks