• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sequence Input Stream  RSS feed

 
Laxmi Bhavisetti
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi, when im trying to compile it. its notifying me Null Point Exception in thread main (java.lang.NullPointerException)
at java.io.SequenceInputStream.nextStream(Unknown source)
at java.io.SequenceInputStream.<init>(Unknown source)
at SequenceInputStreamDemo.main(SequenceInputStreamDemo.java:35).

This is the error im facing.
Can some one help me out please
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Laxmi Bhavisetti wrote:This is the error im facing.
Can some one help me out please

Well, I'm no expert on this particular class, but it seems to me that you're confusing everything by treating Files like Strings; they're not, and they never will be.
Why not just set up an Enumeration<FileInputStream> and populate it with Files? An awful lot easier (and, I suspect, the way the class was designed to be used).

However, simply put, I suspect that your try...catch clause is returning a null.

Winston

 
Paul Clapham
Sheriff
Posts: 22816
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:However, simply put, I suspect that your try...catch clause is returning a null.


Yes, that probably wasn't the best way to handle the case where bad data was encountered. The best way to handle it would be to just let the nextElement() method throw the IOException, but that way isn't available since Enumeration.nextElement() isn't allowed to throw any exceptions. (Except NoSuchElementException, which wouldn't be appropriate in this case.)

What I would do would be to throw some unchecked exception which wrapped the IOException. Let's see... what have we got to choose from under RuntimeException? Maybe IllegalArgumentException isn't a bad choice? We could create our own subclass of RuntimeException, which might be a good idea depending on how architected you wanted your system to be, but let's just go with IllegalArgumentException to demonstrate the general idea:


This still results in unexpected exceptions being thrown, but at least they are easier to understand then the obscure one that the existing code throws.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!