I receive a
error when trying to filter a list and then assign the results to a new list. I have edited the code so it is an int that throws the exception so it isn't the presence of a string that is causing the error -
java.lang.NumberFormatException: For input string: ""DepDelayMinutes""
. I believe the issue is because of the two sets of double quotes but I do not understand how they came about. The original dataset does not have any quotes whatsoever.
java.lang.NumberFormatException: For input string: ""0914""
Thank you very much to all who reply.
Tom Storm wrote:I believe the issue is because of the two sets of double quotes but I do not understand how they came about. The original dataset does not have any quotes whatsoever.
Which is rather odd (although not impossible), because it would appear to be a CSV file. However, without knowing what your ReadCSV class does, it's very difficult to say.
To further Jeanne's suggestion, my advice would be to display the contents of 'list' at line 35. I suspect you may be surprised at what it contains. Your first error would appear to be from trying to process some sort of "label" as an integer, which causes Integer.valueOf() in your filter to throw the exception (I can't see any other obvious place where NumberFormatException would be thrown).
This is one of the problems with Streams - if you don't get them absolutely correct, it can be difficult to spot where (or why) an error is occurring because you're using so many functional abstractions. One possibility might be to rewrite the code procedurally (ie, without Streams), because then you'll be able to print out the data at each stage.
PS: I've broken up some of your lines because they were far too long. Please read the link before you post any more code. Thanks.
Tom Storm wrote:I have tried to replace the stream with little success. I found a library called lambdja and tried to use it but it resulted in null pointer exception. What would be the best way to replace the stream? The code below shows my attempt.
Which still appears to be trying to use a function object. Go back to "old fashioned" ways:which isn't really that much more code than your original. But now you can display the interim values at every point.
However, like I say, we really have no idea what ReadCSV.getData() is doing, so the problem could be there.
Tom Storm wrote:I apologise for the long lines. I wasn't aware how it would scale.
No probs. It's as much for your help, since making threads easy to read will probably get you more answers.
if (Integer.valueOf(delayMins) > 10) ...
involves a "silent" conversion - specifically, an unboxing of the result of Integer.valueOf(). Now, in this case it's highly unlikely to make any difference, but it's worth being aware that they can occur - particularly if the "silent" operation is a box, rather than an unbox.
You have two possible solutions:
if (Integer.parseInt(delayMins) > 10) ...
orWhich one you choose - or even whether you choose to do it - are entirely up to you; but it is worth being aware of these little "gotchas".