Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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] Wed, 09 December 2020 02:43 Go to next message
Michael C Smith Jr is currently offline Michael C Smith JrFriend
Messages: 2
Registered: December 2020
Junior Member
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 09:45 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 576
Registered: August 2016
Senior Member
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] Fri, 11 December 2020 04:13 Go to previous message
Michael C Smith Jr is currently offline Michael C Smith JrFriend
Messages: 2
Registered: December 2020
Junior Member
Thank You
Previous Topic:Problem creating a dynamic web project
Next Topic:Cannot install any plugin
Goto Forum:
  


Current Time: Wed Apr 24 16:17:50 GMT 2024

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

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

Back to the top