• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error when storing filtered list.  RSS feed

 
Tom Storm
Ranch Hand
Posts: 31
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I receive a
java.lang.NumberFormatException: For input string: ""DepDelayMinutes""
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: ""0914""
. 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.



Thank you very much to all who reply.

TS
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
548
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom,
Which line in the program actually throws that error? Can you print out the value of the variables it uses right before that point?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HIH

Winston

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
Ranch Hand
Posts: 31
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Lines 18/19 and 39/40 throw the number format exception. I will attempt to write the code without streams. I apologise for the long lines. I wasn't aware how it would scale.

Thanks,

TS
 
Tom Storm
Ranch Hand
Posts: 31
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.



Thanks,
TS
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Winston
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incidentally, a minor efficiency point:

  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".

Winston
 
Tom Storm
Ranch Hand
Posts: 31
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks very much for your informative post. Very helpful.

Thanks,
TS
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than using wrapper objects, what is wrong with using the primitives?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!