0

Thanks for the help everyone. All problems sorted!

user2990037
  • 289
  • 5
  • 12

3 Answers3

3

never ever ever use == to check equality for strings in Java. you must always use

string1.equals(string2)

the line

if (currentString == "+") 

will always return false, so you must use

if (currentString.equals("+")) 
panini
  • 2,026
  • 19
  • 21
0

The problem is that you do Integer.toString(c) before you check to see if c is numeric.

Also, be aware that you shouldn't compare strings with == you must use .equals(), or you will get unexpected results.

GreyBeardedGeek
  • 27,958
  • 2
  • 46
  • 64
0

I think the problem is that your IF returns "false" in this fragment:

    //Check if the element is a sign
    if(currentElement == "+" || currentElement == "-" || currentElement == "*" || currentElement == "/")
    {
        Log.i("INFORMATION", "Sign found!");
        currentSign = currentElement; //Save into temporary storage to be used next loop
    }
    else // Element is a number
    {
        currentNumber = Double.parseDouble( currentElement ); //Convert number to integer
    }

So you get fatal error when you try to execute Double.parseDouble(currentElement) with currentElement="+".

I would use string comparison instead of "==", like this:

if("+".equals(currentElement) || "-".equals(currentElement) ... etc