Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8804941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:44:18+00:00 2026-06-14T01:44:18+00:00

I have to parse a string which contains a formula for my java project

  • 0

I have to parse a string which contains a formula for my java project and I wanted to use the package exp4j (http://www.objecthunter.net/exp4j/index.html) to do so. But I always get the same error. Its probably really stupid, but sadly I’m missing it. So here is, what I tried:

I simply tried this for testing:

import de.congrace.exp4j.Calculable;
import de.congrace.exp4j.ExpressionBuilder;

public class Tester {
  public static void main (String[] args){
    Calculable calc = new ExpressionBuilder("3+2").build();
  }
}

Now eclipse tells me Unhandled exception type UnknownFunctionExpression and Unhandled exception type UnparsableExpressionException.

After that I tried just using one of the examples on the mentioned website:

import de.congrace.exp4j.Calculable;
import de.congrace.exp4j.ExpressionBuilder;

public class Tester {
  public static void main (String[] args){
    double varX = 2;
    double varY = 3;

    Calculable calc = new ExpressionBuilder("3 * sin(y) - 2 / (x - 2)")
      .withVariable("x", varX)
      .withVariable("y", varY)
      .build();
    double result1=calc.calculate();
  }
}

resulting in the same exceptions as above.

Sorry for any bad english, I’m german and thanks for any help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:44:19+00:00Added an answer on June 14, 2026 at 1:44 am

    The error tells you that a checked exception might occur, so you have to handle it yourself.

    you could either use try/catch to handle it or just declare the exception using throws clause

    public static void main (String[] args) throws UnparsableExpressionException{
    
        Calculable calc = new ExpressionBuilder("3+2").build();
    
    }
    

    or you can wrap the code in a try/catch to handle the exception.

    try {
        Calculable calc = new ExpressionBuilder("3+2").build();
    }
    catch(UnparsableExpressionException ex){
    ex.printstacktrace();
    }
    

    follow the same for UnknownFunctionExpression as well.
    and read about Exceptional Handling in java here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I have to parse a set of dynamic strings which contains
I have a string data which I need to parse into a dictionary object.
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
If I have a string which contains proper xml format and I want to
I have a string which contains the graph data something like this.. string sGraph
I have a string that contains an int. How can I parse the int
I have a list which contains some strings like below: List<String> l = new
I have a string which contains, lets say word key 5 times. Each time
In my XSLT, I have a variable which contains a string. This string contains
I have a string which contains date and has a format of MMMyy. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.