Skip to main content



      Home
Home » Newcomers » Newcomers » Exception in thread "main" java.lang.Error: Unresolved compilation problem:(Syntax error insert "}" to complete ClassBody )
Exception in thread "main" java.lang.Error: Unresolved compilation problem: [message #1835626] Tue, 08 December 2020 21:43 Go to next message
Eclipse UserFriend
package calcengine;

public class Calcengine {
//block statements & switch statements, loops arrays//
public static void main(String[] args) {
double[] leftVals = {100.0d, 25.0d, 225.0d, 11.0d};
double[] rightVals = {50.0d, 92.0d, 17.0d, 3.0d};
char[]opCodes = {'d', 'a', 's', 'm'};
double [] results = new double [opCodes.length];

if (args.length == 0) {
for(int i = 0;i < opCodes.length; i++) {
results[i]= execute(opCodes[i], leftVals[i], rightVals[i]);
}
for(double currentResult : results)
System.out.println(currentResult);
} else if(args.length == 3)
handleCommandLine(args);
else
System.out.println("Please provide an operation code and 2 numeric values");
}

private static void handleCommandLine(String[] args) {
char opCode = args[0].charAt(0);
double leftVal = Double.parseDouble(args[1]);
double rightVal = Double.parseDouble(args[2]);
double result = execute(opCode, leftVal, rightVal);
System.out.println(result);

}

static double execute(char opCode, double leftVal, double rightVal) {
double result;
switch(opCode) {
case 'a':
result = leftVal + rightVal;
break;

case 's':
result = leftVal - rightVal;
break;

case 'm':
result = leftVal * rightVal;
break;

case 'd':
result = rightVal != 0? leftVal / rightVal : 0.0d;
break;

default:
System.out.println("Invalid opCode: " + opCode);
result =0.0d;
break;
}
return result;
}

Syntax error insert "}" to complete ClassBody -I don't know why I am seeing this error

I receive the error Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at calcengine.Calcengine.main(Calcengine.java:5)
Re: Exception in thread "main" java.lang.Error: Unresolved compilation problem: [message #1835638 is a reply to message #1835626] Wed, 09 December 2020 04:45 Go to previous messageGo to next message
Eclipse UserFriend
The error is shown because the source is lacking a final "}", as the error message says.

You then tried to run the code anyway, and then you correctly got the exception.

You should have seen error markers in Eclipse, and you should have gotten a warning dialog when trying to run this via Eclipse that told you that there were still compilation problems.
Re: Exception in thread "main" java.lang.Error: Unresolved compilation problem: [message #1835729 is a reply to message #1835638] Thu, 10 December 2020 23:13 Go to previous message
Eclipse UserFriend
Thank You
Previous Topic:Problem creating a dynamic web project
Next Topic:Cannot install any plugin
Goto Forum:
  


Current Time: Wed May 28 22:15:25 EDT 2025

Powered by FUDForum. Page generated in 0.11863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top