0

Needing some simple help here. Basically, I've got this line:

String stringA = numA.getText().toString();

However, the numA editText that this is using also has a DecimalFormat method called on it before it gets to this point, which makes the out put look like: $###,###,###.00. So, when I go to call getText on numA, it crashes. I'm assuming this is because of the $ sign or commas. How would I change this code so that getText only catches the numbers and not the $ sign or commas?

REAL O G
  • 693
  • 7
  • 23
  • Please post the stack trace of the Exception you are getting, along with the code generating it (marking the line which throws the exception). – azurefrog Oct 30 '14 at 19:13

2 Answers2

1

when I go to call getText on numA, it crashes

The only possible thing is your EditText numA is NULL.

Update:

Look at Better way to Format Currency Input editText?

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • No, it isn't because it is `NULL`. The method actually checks for it using an `if` clause before anything happens to it. The method was actually working before I set the DecimalFormat as I stated. – REAL O G Oct 30 '14 at 19:06
  • `toString()` return any class declaration which the method returns. So only one possibilities is your `getText()` rerun `NULL`. Check for actual exception post stack trace with question. – user370305 Oct 30 '14 at 19:08
  • This is the actual exception upon last run: java.lang.NumberFormatException: Invalid double: "$4,700.15" – REAL O G Oct 30 '14 at 19:09
  • Yupp.. As I told you .. Now put complete stack trace with code in your question. – user370305 Oct 30 '14 at 19:10
1

try this:

String stringA = numA.getText().toString().replace("$", "").replace(",", "");
Shahzad
  • 2,033
  • 1
  • 16
  • 23