Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Compilation error.

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make an arithmetic expression calculator based on input I put on the console. I keep getting the error below. Any ideas how to fix this.
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor ExpressionTree(String) is undefined
Syntax error on token "Calc", delete this token
The method evaluate() is undefined for the type String
at ExpressionTree$PrefixCalc.main(ExpressionTree.java:110)"




 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiler errors can sometimes be mystifying, but in this case it is telling you exactly what the problem is. You are passing a String into the ExpressionTree constructor. The constructor for that class doesn't take a String, however; it takes a different kind of object. Fortunately you do have what it needs close to hand. Check the constructor, then check how you try to invoke it.
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tonks Gabriel wrote:I'm trying to make an arithmetic expression calculator based on input I put on the console. I keep getting the error below. Any ideas how to fix this.
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor ExpressionTree(String) is undefined
Syntax error on token "Calc", delete this token
The method evaluate() is undefined for the type String
at ExpressionTree$PrefixCalc.main(ExpressionTree.java:110)"


The compiler message is quite explicit. It's telling you that your ExpressionTree class doesn't have a constructor that takes a String; and it doesn't.
The only one you've defined takes a Scanner.

Winston
 
Tonks Gabriel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have fixed it. I run it and inputted "(34*65)" in the console. It doesn't show anything. Any tips?


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tonks Gabriel wrote:Ok I have fixed it. I run it and inputted "(34*65)" in the console. It doesn't show anything. Any tips?



Do what the pros do: Either add a bunch of print statements or use a debugger, so that you can see which code is getting executed and what various relevant values are at each step.
 
Tonks Gabriel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone know how to fix this?

java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]

There was also a pop-up screen that it say obsolete method.
 
You have to be odd to be #1 - Seuss. An odd little ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic