Chapter 3: Java - Part 14
So it seems to be working. At least at first. But now try something else. Create a new Diner, and, without changing its first order, select out of its EditText. When the order EditText loses focus with $0.00 as its Text, the app crashes. That's a problem we need to fix. This is an excellent opportunity to go over debugging. Keeping the AVD open, let's go into the Debug perspective by clicking the Debug button on the top-right.
Then find the LogCat window. This window will help us find where the problem is, and is vital to debuggin'. I suggest you expand the size of the LogCat window beyond its default size.
It may also behoove you to click the Scroll Lock button at the top-right corner of the window. This sometimes makes it easier to navigate the LogCat window. I say 'sometimes' because I find Eclipse's scrolling to be a bit janky. Sometimes I need to use the Scroll Lock button, and sometimes the default scrolling behaves well enough that I don't need to. Also, occasionally, the Scroll Lock button just doesn't work. It's probably something wrong on my end, but I thought I'd mention it.
Now look at the text in LogCat. We're looking for a big block of red text (red is bad; it refers to errors). Depending on how long you've had your AVD open, you may need to scroll down to find it. When you do find it, it'll look something like this:
Take note of the parts I circled. Right near the start of the red text, you should find a line that complains about a NumberFormatException. Specifically, the computer found an Invalid double. The invalid double is $0.00. A few lines down, Eclipse tells us that the error happens on line 48, in the method updateTotal, which is in the Diner file in the package glaukon.tutorials.tipcalc.Note that it may say a different line number for you, depending on how you spaced and formatted your code. So, what this is telling us is that when we deselected an order EditText that had $0.00 as its Text, the computer decided that the $0.00 was not a proper double. And it's right. 0.00 is a double, but $0.00 is not. There is no way for the Double.parseDouble method to convert the $ in $0.00 into a double. So we need to get rid of the $ before we use Double.parseDouble. Let's work on that.
Glossary
Debug Perspective: The debug perspective arranges Eclipse's windows in such a way as to emphasize the process of debugging. Basically, it makes the UI more geared towards finding and squashing bugs.
LogCat: The LogCat window lets you see a list of messages outputted by the computer that can help you locate where a bug occurs.