Thanks for the help everyone. All problems sorted!
Asked
Active
Viewed 80 times
0
-
Post less code next time. – cbmanica Nov 14 '13 at 00:40
-
Try searching the question before posting. This is a duplicate. – JoxTraex Nov 14 '13 at 02:56
3 Answers
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
-
the same goes for all other places where you aren't using .equals() when checking strings. – panini Nov 14 '13 at 00:40
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
-
c is an int to start with (its the for loop counter), so that shouldn't be an issue. – panini Nov 14 '13 at 00:42
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
Ivan Berloga
- 53
- 8